Parsing Quantifier {x,y} Following Nothing Considered Harmful

If you normally do a Regex.Escape(string) in C# to get some text ready for use as a regular expression, be aware that a string like ^Lijit (+http://www.lijit.com/)$ will be escaped like so ^Lijit\ \(+http://www\.lijit\.com/\)$ instead of ^Lijit\ \(\+http://www\.lijit\.com/\)$ as you would expect.

Using that "escaped" regular expression will result in an ArgumentException along the lines of parsing "^Lijit (+http://www.lijit.com/)$" - Quantifier {x,y} following nothing. That message is virtually un-Google-able until now.

The .NET exception occurs, I think, because the parser just doesn't understand the unescaped quantifier being next to an escaped control character. I believe that the escaping misses it because it uses that same parser because the plus sign is definitely one of the characters that the Escape method can handle.

About this Entry

This page contains a single entry by bbrown published on January 2, 2007 12:37 PM.

New Year's Resolutions was the previous entry in this blog.

Blogging By the Numbers is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Feedback to