Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RegExp backreference error 1

Status
Not open for further replies.

KristianW

Programmer
Nov 5, 2003
9
NL
Hello all.

I am trying to replace some text in a variable via the use of the REReplaceNoCase function:

<cfset MyVariable = REReplaceNoCase(MyVariable,"(href="")([A-Z0-9])","\1#cgi.script_name#?#Path#\2","ALL")>

This is designed to change the any hyperlinks contained in MyVariable to become relative to the current location.

However, on processing, I get a "BAD BACKREFERENCE" error thrown from this line, and I can't seem to get around this. If I insert a space between the "\1" and "#cgi.script_name#", the page processes, but of course I don't want the space in the hyperlink! (could possibly put another REReplace line after this line removing the space, but I'd rather not, and shouldn't have to!)

Finding information on this problem has proved exceedingly difficult, so I'm hoping some of the CF gurus out there may have seen this before. Most likely something painfully obvious staring me in the face, but I can't seem to see it. If ANYONE has any tips / suggestions, they will be warmly welcomed!

Thanks,
K.
 
It's lame.. I know.. try this..

Code:
<cfset MyVariable = REReplaceNoCase(MyVariable,"(href="")([A-Z0-9])","\1
#cgi.script_name#?#Path#\2","ALL")>

Note the return after the \1.. That will show up in source but shouldn't on your page.

I've done a ton of regexes and the backreferences are always nested in the code, but... for some reason here.. that's not working..

Here's a better solution..

Code:
<cfset sname=" " & cgi.script_name>
[code]<cfset MyVariable = REReplaceNoCase(MyVariable,"(href="")([A-Z0-9])","\1#trim(sname)#?#Path#\2","ALL")>

It puts the space in, but trims it right back out..

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Thanks Webmigit!

The second suggestion still threw the exception, but the first option worked a treat. Code looks messy, but hey - it works! If only Macromedia had more resources on this (and SEVERAL other topics), life would be easier....

Thanks again,
K.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top