tags:

views:

32

answers:

2

I have a string like this that is delimited | and can contain any character in between:

"one two|three four five|six \| seven eight|nine"

I'd like to find a regex that returns:

one two
three four five
six | seven eight
nine

I can think about how I want to do this but, I don't know regex well enough. I basically want to match until I reach a | that is not preceded by a \. How do I do this? I know there is a back tracker, but I don't know how to do it.

+1  A: 
Regex.Split(input, @"(?<!\\)\|");
  • (?<!\\) - negative lookbehind. There is no preceding \
Matthew Flaschen
+1  A: 
John Kugelman