What about <cfquery.*?</cfquery>

Thanks Ben :OD

Ade

-----Original Message-----
From: chris porter [mailto:[EMAIL PROTECTED]
Sent: 07 March 2005 20:05
To: RegEx
Subject: Re: Finding queries that use a certain table


so this is kinda along the same lines i was asking about in my "matching
stuff between 2 tags" post but a bit easier namely because you will never
have certain characters inside the text between the start & stop tag.. so it
makes it easier to create a refrence point.
the key to this issue is that the ".*" is greedy!!! it will collect
EVERYTHING, and then once its done, the regex engine will look at what its
collected to match the remaining part of the regex (remember regexes return
as much data as possible, not as little). so, if you have info like this:

<cfquery datasource="blah">
select * from sysobjects
</cfquery>
<cfquery datasource="blah">
select * from sysFields
</cfquery>

and you run:
<cfquery(.*)</cfquery>

you will get return data that matches everything from the top to the bottom
of the text (because .* matched everything first).
the solution here is to use negated classes to make the match. Negated
Classes are not greedy they match untill an exception is made to the class
and thats it. thus:

<cfquery[^>]*>([^<]*INSERT_TABLENAME_HERE[^<]*)</cfquery>

something to note: a character class is everything between brackets ie:
[abc] will match either the letter A   or B    or C .  a negated  caracter
class is everything in brackets taht falls after a ^.. eg [^abc] will match
D or E or F or 1 or 5, but not A or B or C.

additional testing will also tell you that the pattern i supplied will fail
if your query uses the "<" sign in the query.. eg: "select * from sysobjects
where id < 12345" will fail. if you are up for doing some learning, read up
on "negative lookahead's and how they would apply to this situation to solve
that problem.

-Chris


> > Can anyone formulate a regex to find all instances of a cfquery
> > statement that involves a particular table, say MyTable?
>
> Yes in HomeSite. <cfquery(.*)?MyTable(.*)?</cfquery> doesn't work. It
> finds the first instance of <cfquery and the last of </cfquery> and
> everything in between, not each instance...
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.6.2 - Release Date: 04/03/2005


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Protect your mail server with built in anti-virus protection. It's not only 
good for you, it's good for everybody.
http://www.houseoffusion.com/banners/view.cfm?bannerid=39

Message: http://www.houseoffusion.com/lists.cfm/link=i:21:849
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/21
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:21
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.21
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to