I want to write a javascrpit code with .Split() that split a s开发者_StackOverflow中文版tring with structure described below:
The input:
W1...Wn=>S1...||...Sm||Sj...Sk|Y1...Yn=>D1...Di||Dm...Dn|...
The Output:
W1...Wn=>S1...||...Sm||Sj...Sk
Y1...Yn=>D1...Di||Dm...Dn
...
I've seen the question that split this string: a=>aa|b=>b||b|c=>cc . but my question is general case of that question.
please help me...
Thanks...
match
is easier to use here:
'W1W2W3=>S1S2S3||S4S5||S6S7S8|Y1Y2Y3=>D1D2D3||D4D5|D6'.match(/(?:\w|=>|\|\|)+/g);
// ["W1W2W3=>S1S2S3||S4S5||S6S7S8", "Y1Y2Y3=>D1D2D3||D4D5", "D6"]
Same method.
.split(/\|(?=\w+=>)/);
精彩评论