We would like to split a string on instances of the pipe character |, but not if that character is preceded by an escape character, e.g. \|.
ex we would like to see the following string split into the following components
1|2|3\|4|5
1
2
3\|4
5
I’m expecting to be able to use the following javascript function, split, which takes a regular expression. What regex would I pass to split? We are cross platform and would like to support current and previous versions (1 version back) of IE, FF, and Chrome if possible.
Instead of a split, do a global match (the same way a lexical analyzer would):
\\or|Something like this:
A quick explanation:
([^\\|]|\\.)matches either any character except'\'and'|'(pattern:[^\\|]) or (pattern:|) it matches any escaped character (pattern:\\.). The+after it tells it to match the previous once or more: the pattern([^\\|]|\\.)will therefor be matches once or more. Thegat the end of the regex literal tells the JavaScript regex engine to match the pattern globally instead of matching it just once.