In Javascript, I have a situation where I get input which I .split(/[ \n\t]/g) into an array. The point is that if a space is directly preceded by a backslash, I don’t want the split to happen there.
E.g. is_multiply___spaced_text -> ['is','multiply','','','spaced','text']
But: is\_multiply\___spaced_text -> ['is multiply ','','spaced','text']
(Underscores used for spaces for clarity)
If this wasn’t Javascript (which doesn’t support lookbehinds in regex’es), I’d just use /(?<!\\)[ \n\t]/g. That doesn’t work, so what would be the best way to handle this?
You can reverse the string, then use negative lookahead and then reverse the strings in the array:
In this example, the result should be: