Suppose the portion that needs to be captured by regex is indicated by PORTION in the following string
,"PORTION","","a",["some_string"]
Examples of PORTION are
- \"abc123
- abc123\"
- \"abc123\"
- abc\"123\"
- abc123
so the strings actually look like
- ,"\"abc123","","a",["some_string"]
- ,"abc123\" ","","a",["some_string"]
- "\"abc123\"","","a",["some_string"]
- "abc\"123\"","","a",["some_string"]
- "abc123","","a",["some_string"]
PORTION is surrounded by double quotes. Double quotes inside PORTION are escaped by backslash. My current pattern is
my $pattern = '(.?([\\"]|[^"][^,][^"])*)';
which produces the results for the above examples as follows
- \"abc123","","a"
- abc123
- \"abc12
- abc\"123\""
- abc123"
The pattern tries to match everything in front of a sequence that is not ","
and also allow the capturing of \"
But it's not working as intended.
How can I make it work?