StrataFrame Forum

Need help creating RegEx expression...

http://forum.strataframe.net/Topic2238.aspx

By StarkMike - 8/17/2006

These are my examples:



SELECT *

INTO #TEMP

FROM TABLE



SELECT * INTO #TEMP FROM TABLE



I would like some help creating a RegEx pattern to find the word INTO followed by a space then a pound sign (#) then a wildcard for the temp table name then another space.



Thanks
By StrataFrame Team - 8/17/2006

System.Text.RegularExpressions.RegEx.IsMatch(myvalue, "into #(\w*?)( |$)", System.Text.RegularExpressions.RegexOptions.IgnoreCase Or System.Text.RegularExpressions.RegexOptions.Multiline)

The actual recular expression would be this:

into #(\w*?)( |$)

Make sure you use RegexOptions values so that the "into" will match "INTO" and so that the $ will match the end of a line.

By StarkMike - 8/17/2006

Thanks! Would you mind briefly explaining to me how you created that expression? I'm new to RegEx expressions and having a hard time understanding how they work.

The expression you created will find the INTO statement whether it is on a line by itsself or on one line with the rest of the SQL statement?

By Trent L. Taylor - 8/17/2006

This is a very long a deep topic.  One thing I might suggest is purchasing a copy of RegExBuddy (http://www.regexbuddy.com/) which will allow you to create and test expressions within an editor.  You can then take those expressions and import them over to .NET.

There is really no such thing as a "brief" explanation when it comes to RegEx. w00t

By StrataFrame Team - 8/17/2006

I think it's only like $29 or something like that.

As for finding the INTO if it's on it's own line, no, you'll need to replace the first " " with a ( |$) or something like that.

By StrataFrame Team - 8/17/2006

RegexBuddy, we use it all the time Smile

By StarkMike - 8/17/2006

Thanks guys! This is awesome information... I've submitted the PO for the RegExBuddy.



The expression wont find the INTO #TEMP on its own line... it'll only find the one thats on the same line. What do I need to change?
By StrataFrame Team - 8/17/2006

Try this:

\binto\b.*?#(\w*)\b

However, use RegexOptions.SingleLine instead of MultiLine.