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...

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble 
Ticket application

http://www.houseoffusion.com/banners/view.cfm?bannerid=48

Message: http://www.houseoffusion.com/lists.cfm/link=i:21:848
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