?
Solved

Negating a multicharacter string in a regular expression

Posted on 2006-05-25
13
Medium Priority
?
463 Views
Last Modified: 2013-12-24
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
0
Comment
Question by:madacebo
  • 6
  • 3
10 Comments
 
LVL 9

Expert Comment

by:73Spyder
ID: 16761400
You could you FindNoCase  

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

This should work for you
0
 

Author Comment

by:madacebo
ID: 16764339
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.
0
 
LVL 9

Expert Comment

by:73Spyder
ID: 16770342
<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.

0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:madacebo
ID: 16771637
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".
0
 
LVL 9

Expert Comment

by:73Spyder
ID: 16771670


<cfif FindNoCase("myString", "abc") EQ 0 >
     REReplaceNoCase(myString,"<a[^>]*>(.*?)</a>", "\1", "ALL")
</cfif>
0
 

Author Comment

by:madacebo
ID: 16771705
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.
0
 
LVL 9

Expert Comment

by:73Spyder
ID: 16771729
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.
0
 
LVL 9

Accepted Solution

by:
73Spyder earned 500 total points
ID: 16771732
Maybe though if the srting could be treated as a list with a " " space   as a delimeter then you could loop though each item in the list

0
 
LVL 25

Assisted Solution

by:dgrafx
dgrafx earned 500 total points
ID: 16775374
You will need to loop your "string" using " " as a delimiter as 73spyder said.
you then look at each string of chars between the spaces (commonly known as words)
and do something like:

<cfset string="this is a <a href='http://www.cfitools.com/'>hello</a> link test">
<cfset string=replacenocase(string,"#chr(60)#a href","#chr(60)#ahref","all")>
<cfloop list="#string#" index="ii" delimiters=" ">
<cfif REFindnocase("(http|ftp|https)://([\w-]+\.)+(/[\w- ./?%&=]*)?", ii)>      <!--- if a link --->
<cfif refindnocase("abc",ii)>
#replacenocase(ii,"#chr(60)#ahref","#chr(60)#a href","all")#
<cfelse>
REMOVED
</cfif>
<cfelse>
#ii#
</cfif>
</cfloop>
0
 
LVL 9

Expert Comment

by:73Spyder
ID: 17084867
No Objection, although dgrafx did provide more detail than I did
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question