Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

RegEx colon patterns like :q

I'm doing RegEx.Matches on a simple CSV string like this:


This is in VB .NET and the string is properly escaped (see below).  I want to find the number of quoted strings in that line, which should be two, since RegEx doesn't do overlaps in the Matches method.  Here are two different possibilities:

Regex.Matches("""Smith"",""Jones""", """[^""]*""").Count

Regex.Matches("""Smith"",""Jones""", ":q").Count

The .NET Documentation tells me that these patterns should return the same thing; but in fact the first works (and returns 2), but the second returns 0.

*Using a RegEx object with the match pattern in the constructor makes no difference
*I get the same results in C#
*None of the other : patterns seem to work either
*I'm using VS .NET 2002 Academic
*The : patterns _do_ work in Find in the VS .NET IDE.

Can anyone shed some light on this situation, and especially on why the : patterns don't work in my code?

Monday, April 19, 2004

Sorry,  but I'm not a huge .NET expert and I've never seen those character classes before (:q, :...).

It looks like they're invalid as:

Regex.Matches(":q",":q").Count; // 1

What MSDN docs are you reading?

Monday, April 19, 2004

The Regexes in the VS.NET IDE are completely different to the ones in the framework. Annoying but true. They're a hangover from previous versions of the IDE (Developer Studio).

In the ".NET Framework General Reference" look for the topic "Regular Expression Language Elements".

Use the Regulator to test your .NET Regexes:

Duncan Smart
Monday, April 19, 2004

"What MSDN docs are you reading?"


Monday, April 19, 2004

You should be looking at:


Duncan Smart
Monday, April 19, 2004

Yeah, now that I think back, I've never actually used RegEx in code before; all the regular expression stuff I did was on text files open in the IDE, where the :q thing works.

Well, at least I've got a valid expression to do what I need to do; mostly I was just curious why what I thought would work didn't work.  And now I've learned something new, saving future head-beatings-against-wall.  Thanks to all.

Monday, April 19, 2004

So here's another question: Where do I find a reference list of what characters I can use in .NET regular expressions?  In the .NET Help and online I've found a number of articles that say "Here are a few examples of things you can do..." but that doesn't help me; I'm looking for a list like the VS IDE list I referred to.

Wednesday, April 21, 2004

Here's the full list:

Jon Galloway
Thursday, April 22, 2004

Um...that would be the list that got me mixed up in the first place, the list that includes VS .NET IDE-only syntax.

Thursday, April 22, 2004

*  Recent Topics

*  Fog Creek Home