PC Review


Reply
Thread Tools Rate Thread

Regex.Split oddity

 
 
nick.p.doyle@gmail.com
Guest
Posts: n/a
 
      22nd Feb 2005
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!

 
Reply With Quote
 
 
 
 
nick.p.doyle@gmail.com
Guest
Posts: n/a
 
      22nd Feb 2005
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")

 
Reply With Quote
 
nick.p.doyle@gmail.com
Guest
Posts: n/a
 
      22nd Feb 2005
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regex.Split... Can I do this?? Jordi Rico Microsoft VB .NET 7 17th Oct 2006 11:54 PM
To split, or to regex Tony Microsoft C# .NET 4 29th Sep 2006 03:29 AM
Re: Split or Regex Matt Microsoft C# .NET 1 8th Aug 2003 05:30 PM
Re: Split or Regex Stephen Alpert Microsoft C# .NET 0 8th Aug 2003 05:27 PM
Re: Split or Regex Scott Carter Microsoft C# .NET 0 7th Aug 2003 08:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:22 AM.