I read a line from a file that I split on | character. For example, the line
1|test pattern|prefix|url|postfix
So a split should always give me 5 substrings, which in the case above
["1", "test pattern", "prefix", "url", "postfix"]
A problem occurs when any of these five substrings contains | character. I would save him as an escaped \ |
1|test pattern|prefix|url \| title |postfix
Now you can see that string.split ('|') will not give me the desired result. Desired Result:
["1", "test pattern", "prefix", "url \| title ", "postfix"]
I tried some regular expressions, but none of them give the desired result.
string.split(/[^\\]\|/) //["", "", "prefi", "$url \| $titl", " postfix"]
It seems like this is only possible with negative callbacks, but I couldn't get it to work
source
share