Jeremy Allen said:
> <CFSET strFoo = REReplaceNoCase(strFoo,"</?script.*>","<BAD>","ALL")>
> the "script.*" portion of the regex searches ALL the way
> to the end of the string and then it goes backwards one
> character at a time until it finds the closing ">"
> How to fix this?
> $strFoo =~ s/<\/?script.*?>/<BAD>/ig;

You are correct in your non-greedy needs.  :)  Quick lesson on
greedy (.*) versus non-greedy (.*?).  (More for the benefit of
the list than you in particular.)  The documentation you read
on greedy versus non-greedy is correct, if a bit confusing.

"The question [sic] mark says to backtrack fowards in stead of
 backtrack backwards."

Basically, think of it this way: as you said, the ".*>" finds the
last occurance of ">" that it can.  In technical jargon, we say
that it "slurps" everything in between, which is why we call it
greedy.  Non-greedy, then, does the exact opposite: it finds the
first match of ">" that it can and only slurps up the bare minimum.

Now, having said all of that, I'm going to tell you that CF
doesn't seem to have non-greedy matching for regexs.  (At least,
not as near as I've been able to figure out.)  Even Perl only
finally just got them in version 5.  (Right?  I think.)

The workaround?  It's not as elegant, but it's not too bad:

</?script[^>]*>

Basically, if you can't read regex, it's just saying that you
want to match any character that's not a ">", zero or more times.
Since it's not ".*", it's not greedy.  Pretty much exactly what
you need.

Of course, this has problems with the following scenario:

<script type="JavaScript" hack=">">

But technically, that's not legal HTML anyway.

>My conclusion is this.. ColdFusion and Javascript regex
>are crippled..

Slightly.  :)

-Rick

------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/[email protected]/
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to