the .* is greedy. and the ? makes the entire matchset of the .* optional. if 
you really look at what it does, the ? will never actually do anything. take 
for example the text:
<cfquery></cfquery>

if you analyze the regex, you have these areas:
<cfquery
...*?
</cfquery>

well the obvious match looks like this:
<cfquery    <cfquery

but what about the .*? it matches the >
<cfquery    <cfquery
...*?         >
</cfquery>  </cfquery>


so what if your searchtext looked like this:
<cfquery</cfquery>      (yes i deliberately left out the ">")

the searchresult would be something like this:
<cfquery    <cfquery
...*?         (optional kicked in since nothing was there.. but wich one)
</cfquery>  </cfquery>


keep in mind that the * means 0 or more occurances.. so you basically just said 
"match anything 0 or more times optionally" which doesnt make sense really 
since optional is technically part of the * anyways.

now using the .* still has the problem of being greedy so take this data:
<cfquery>hi there</cfquery><cfquery>hello world</cfquery>

if you parse it with:
<cfquery.*</cfquery>

your matches will look like this:
<cfquery         <cfquery
...*               >hi there</cfquery><cfquery>hello world
</cfquery>       </cfquery>


it seems weird at first, but you have to realize that the REGEX engine wants to 
give you a match.. and it tries really really hard to.. but it also has to take 
what you ask literally, so when you say "give me everything"... translated to 
".*" it grabs everything.. then when you say "give me everything upto 
something".. the regex enging grabs everything, then starts at the end (this 
process is called backtracking) and works it way to the beginning checking to 
see if 'something' is there. 

Hope this helps:
-Chris

>What about <cfquery.*?</cfquery>
>
>Thanks Ben :OD
>
>Ade
>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Find out how CFTicket can increase your company's customer support 
efficiency by 100%
http://www.houseoffusion.com/banners/view.cfm?bannerid=49

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