Regex.Split oddity

  • Thread starter Thread starter nick.p.doyle
  • Start date Start date
N

nick.p.doyle

Hallo,
Am splitting on quoted strings first, then operators e.g.
a = Regex.Split( "a and ""b and c""", "("".+?"")|( and )")
I expect a=("a", " and ", """b and c""")
I receive a=("a", ""b and c"")
(empty strings ignored)
Help appreciated!
 
In fact I have made a far simpler test :
a = Regex.Split("a b c", "(a)|(b)")
Yields a = ("", "a", " ", " c")
when it should be a = ("", "a", " ", "b", " c")
 
I have gotten around the problem by using Regexp.Matches instead
HOWEVER
this looks like a bug in .net regexps to the tune of
"Non-first matches in Regexp.Split will not be included in the output
array".
Tsk.
 
Back
Top