Link to home
Start Free TrialLog in
Avatar of madacebo
madacebo

asked on

Negating a multicharacter string in a regular expression

How do you negate a multicharacter string in a regular expression (to use in REReplace)?

For example, what RE would I use to match a hyperlink (<a href="URL">Text</a>) such that the URL does not contain the string "abc"?  It CAN contain any of those characters or any other combination of them.

Thanks
Avatar of 73Spyder
73Spyder

You could you FindNoCase  

http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/functi81.htm

This should work for you
Avatar of madacebo

ASKER

I don't see how FindNoCase will help; I definitely need to use regular expressions.  What I'm looking for is an RE for the example I gave above.
<cfset variables.hyperlink = "text">  //  or set this to what ever the hyperlink is

<cfif FindNoCase("#variables.hyperlink#", "abc") EQ 0 >
     <a href="URL">Text</a>          //-- put code here if "abc" is not found
<cfelse>
  CODE if "abc" is found
</cfif>



If this is not it,  maybe I am missing the point of the question.  Could you provide a few more details.

I want to use REReplace to remove all hyperlinks from a string except for those that have "abc" in the link tag.  Something like:

REReplaceNoCase(myString,"<a[^>]*>(.*?)</a>", "\1", "ALL")

but where [^>]* can't match "abc".


<cfif FindNoCase("myString", "abc") EQ 0 >
     REReplaceNoCase(myString,"<a[^>]*>(.*?)</a>", "\1", "ALL")
</cfif>
The string has multiple links in it.  Your suggestion (without the quotes around the first myString) will cause all of the links to be saved even if only one of them should be saved.

What I'm currently doing is running the string through REReplace once and changing the hyperlinks that DO contain the string to something else, then running the REReplace from my previous comment, then using a third REReplace to change the saved ones back to their original format.

I want to know if there's an RE I can use to do this in one step rather than three.
Ah...  I see now.

Sorry for the confusion.   I am not sure that there is a better way than the process that you are already going through.
ASKER CERTIFIED SOLUTION
Avatar of 73Spyder
73Spyder

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of dgrafx
dgrafx
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No Objection, although dgrafx did provide more detail than I did