Regular Expression Insanity

D

Don

I've created a regular expression to match everything from the word "const"
to the end of the last line that doesn't end in a space-underscore
characters.

i.e.


\sConst\s(.*)\sAs\s*String\s*=(.*\s_\n)*(.*\n)


applied to:


Friend const foo as string = "line1" & _
" line2" & _
" line3" & _
" line4" _
& " line5" & _
" end"
Friend const...


gives me:


const foo as string = "line1" & _
" line2" & _
" line3" & _
" line4" _
& " line5" & _
" end"


This works in the Regex Coach program I used to help me build the
expression, but when I bring this over to VB.NET, it only matches this:


"goodbye" & _

(with a hard return at the end)


Is there something wrong with the Regex Coach program in that is is
improperly executing my regular expression, or is VB.NET doing something
wrong?

Oh, and here's the code snippet that is retrieving the collection of Match
objects:


matches = Regex.Matches(sourceString, EXPRESSION, _
RegexOptions.IgnoreCase Or RegexOptions.Compiled)

(sourceString is the string I'm processing, and EXPRESSION is the
regular expression as listed above)


- Don
 
D

Don

Okay. Two things:


1. It appears the program I was using to help me build the regular
expression -- RegEx Coach -- is not compatible with the regular expression
language used by .NET. Fortunately I found an alternative program called
Expresso ( http://www.ultrapico.com/Expresso.htm ) which was programmed for
..NET regular expressions. Program registration is free.


2. Take this you RegEx motherf$#%er! :

(\sConst\s(.*)\sAs\s*String\s*=)(.*\s_.*\n)*.*\n


- Don
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top