开发者

Regex to split following line into various fields?

开发者 https://www.devze.com 2023-02-25 02:35 出处:网络
I am new t开发者_Python百科o regex. Need some help. I want to have a regex that would give me the following o/p for given i/p in java.

I am new t开发者_Python百科o regex.

Need some help.

I want to have a regex that would give me the following o/p for given i/p in java.

Input string

1. AB,CD,EF,GH     
2. AB,"CD,EF",GH
3. AB|CD|EF|GH
4. AB|EF"A" "|GH

Expected Output

Note : E.g For 1st string, I want AB CD EF GH to be 4 different array elements of the same array. Similarly for next i/ps

1. AB  CD  EF  GH  
2. AB  "CD,EF"  GH
3. AB  CD  EF  GH
4. AB  EF"A" "  GH  

Thanks.


From 3) and 4) you want to match sequences of letters not containing | characters, while from 1) you want to match sequences of letters not containing commas. And this has to happen at the same time, so that the sequence can't contain either character.

Alternatively, 2) allows the sequence to contain a comma, as long as it begins with a quote, in which case it runs up until the next quote.


Is it required for your homework this to be regex? It seems like you can just scan each line character by character and replace the , with a space easily.

0

精彩评论

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