.* will match everything in a greedy manner

.*? will match everything in a non-greedy manner.

That means that the first one may take out more than you want, or the second one may not take out as much as you want depending on the situation

e.g.

<cfsavecontent variable="str">
  <cfoutput>
    <table>
      <tr>
        <td>Some Text</td>
      </tr>
    </table>
    <br>
    <br>
  </cfoutput>
</cfsavecontent>

<cfset innerString1 = reReplaceNoCase(str,'(<t[^>]*>)(.*)(</t[^>]*>)','\2','all')>

<cfset innerString2 = reReplaceNoCase(str,'(<t[^>]*>)(.*?)(</t[^>]*>)','\2','all')>

<cfoutput>
GREEDY:
#HTMLCodeFormat(innerString1)#

NON GREEDY:
#HTMLCodeFormat(innerString2)#

</cfoutput>

In your case it doesn't make any difference. I just tend to make regexes non-greedy unless I specifically want them to be greedy. I find it makes it easier to build complex expressions that way.

Spike


Mark M wrote:
<cfset innerStr = 
reReplaceNoCase(str,'(.*<h1.*?>)(.*?)(</h1>.*)','\2','all')>
    

Spike - 

Thanks, that helps alot.

I've actually modified it to make it a tad less greedy - 
title = reReplaceNoCase(form.help,"([^<]*<h1>)([^<]*)(</h1>.*)","\2","one");

As there may be more than 1 <h1> header on a page.
(and it's controlled output, so there will be no class on the <h1> tag)

But stupid question - whats the difference between (.*) or (.*?) seems kinda 
pointless to me?

Cheers,

Mark

-----------------------------------
[EMAIL PROTECTED]       
ICQ: 3094740
Safe From Bees
[www.safefrombees.com]

---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]

MX Downunder AsiaPac DevCon - http://mxdu.com/


  

-- 
Stephen Milligan
Consultant for hire
http://www.spike.org.uk
---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]

MX Downunder AsiaPac DevCon - http://mxdu.com/

Reply via email to