That solution will only work in Perl. The CF regex engine cannot handle non-greedy matching. If you do more than a little work with regexes you may want to consider downloading my (completely free) PCRegEx CFX tag, which gives CF Server Perl-Compatible regexes, including non-greedy matching. URLs are at the bottom of this message.
As far as a one-line regex for pasting into CFStudio, try this: <CFQUERY[^>]*>(([^#<]|<[^/])*#(Form|URL)\.[^#]+#)+([^#<]|<[^/])*</CFQUERY> It worked on the following test cases: <CFQUERY DATASOURCE="foo">delete from foo where bar = #Form.baz#</CFQUERY> <CFQUERY DATASOURCE="foo">delete from foo where bar = #Form.baz# and quux = 1</CFQUERY> <CFQUERY DATASOURCE="foo">delete from foo where bar < #URL.fark#</CFQUERY> <CFQUERY DATASOURCE="foo">delete from foo where quux = 1</CFQUERY> <CFQUERY DATASOURCE="foo">#Form.Query#</CFQUERY> That is, it correctly matched all but line 4. Unfortunately, it will *not* correctly match the following case: <CFQUERY DATASOURCE="foo">#PreserveSingleQuotes(Form.Query)#</CFQUERY> That is, a case where there is a Form/URL variable, but it is not referenced directly with octothorpes. Those are *much* harder to find correctly. You can try this: <CFQUERY[^>]*>([^UF<]|F[^o]?[^r]?[^m]?[^.]?|U[^R]?[^L]?[^.]?|<[^/])+(Form\.| URL\.)([^<]|<[^/])+</CFQUERY> But it runs *very* slowly. It took a few seconds just to find the 5 that match from this email! If you can say with confidence that you don't have function-wrapped Form/URL variables, you should definitely use the first case. Actually, your best bet would be a programmatic one in this case, I think. Much safer. HTH, Rick PCRegEx Links: Allaire DevEx - http://devex.allaire.com/developer/gallery/info.cfm?ID=47AA9175-9AFE-11D4-AA A700508B94F380 My site - http://www.rixsoft.com/ColdFusion/CFX/PCRegEx/ -----Original Message----- From: Jerry Johnson [mailto:[EMAIL PROTECTED]] Sent: Friday, December 07, 2001 16:29 To: CF-Talk Subject: Re: regex find form vars in queries? Sure. As they say, Perl is greedy. (as is RegEx.) It grabs the biggest string that matches the criteria. If you don't want it to, but instead grab the smallest. you must qualify the search, using the ? character. So if you have a * or a ?, replace it with a *? or a ??. (I think) Jerry Johnson >>> [EMAIL PROTECTED] 12/07/01 03:58PM >>> I'm missing something here - it seems like it should be straight-forward. I need to find all form (and url) scoped variables in cfqueries. I'm having problems getting the regex to stop at the first </cfquery> - it goes to the last one on the page. Any regex gurus care to give this a try? thanks, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Structure your ColdFusion code with Fusebox. Get the official book at http://www.fusionauthority.com/bkinfo.cfm FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/[email protected]/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

