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 wantAB 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.
精彩评论