When parsing FTX (free text) string, I need to split it using +
as a delimiter, but only when it's not preceded by escape character (say, ?
).
So this string nika ?+ marry = love+sandra ?+ alex = love
should be parsed to two strings: nika + marry = love
and sandra + alex = love
.
Using String.Split('+')
is obviously not enough. Can I achieve it somehow?
One way, it seems to me, is to replace occurrences of ?+
with some unique character (or a succession of characters), say, @#@
, split using "+" as a delimiter and then replace @#@
back to +
, but that's unreliable and wrong in any possible way I can think of.
?
is used as an escape character only in combination with either :
or +
, in any other case it's viewed as a regular character.