开发者

Help for writting a regular expression in JavaScript

开发者 https://www.devze.com 2022-12-29 09:09 出处:网络
I want to write a javascrpit code with .Split() that split a s开发者_StackOverflow中文版tring with structure described below:

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+=>)/);
0

精彩评论

暂无评论...
验证码 换一张
取 消