[thelist] Need a little Regex Help

cspruck at mindspring.com cspruck at mindspring.com
Mon Sep 24 11:54:33 CDT 2001


thelist at lists.evolt.org wrote:
> I'm having difficulty forming a regular expression in ColdFusion >for finding strings that look like the following:
>
>sql="SELECT col1, col2 FROM table WHERE col1 = 1;"
>sql="SELECT col1, col2 FROM table WHERE col2 LIKE 'cow';"
>sql="SELECT col1, col2 FROM table WHERE col2 IS NOT NULL" (notice >lack of ;)
>
>The string will always contain sql=" with a closing ". I've tried >using sql="(.*);"  as my pattern to match, but that's producing some >strange results (like finding everything from the start of the sql=" >pattern to the end of the document (even though it seems to me it >should stop at the first sign of the ; character.

Michael,

I ran the following within CF STudio and it seems to work:

sql="([^"])+"

Basically meaning, find sql=" plus one or more of any other character that isn't a " then the closing ". Note - this only works if each string you need ends with the quote - if it doesn't, it rolls into the next match with something like sql="SELECT whatever WHERE whatever sql=".

Hope this does the trick!
Chris





More information about the thelist mailing list