ColdFusion Rereplace

I am trying to replace some some words from the url but getting the error  message  Malformed regular expression "?target=(top|bottom)".

The url is http://www.kidstuffcatalog.com/return.cfm?target=top

the CF rereplace #rereplace(cookie.lastpage, "?target=(top|bottom)", "","ALL")#
LVL 19
erikTsomikSystem Architect, CF programmer Asked:
Who is Participating?
 
_agx_Commented:
Good explanation.

@erikTsomik - BTW, will the string ever contain other url parameters or could the "target" be in a different position? ie

  http://www.kidstuffcatalog.com/return.cfm?target=top&foo=bar    ... OR
  http://www.kidstuffcatalog.com/return.cfm?foo=bar&target=top 

If so you might need a different expression to avoid breaking the query string. My regex skills are so-so. I am guessing Terry would be of more help with that kind of expression ;-)
0
 
_agx_Commented:
The "?" is a special character in regex's and needs to be escaped:

       reReplaceNoCase(cookie.lastpage, "\?target=(top|bottom)", "","ALL")
0
 
Terry WoodsIT GuruCommented:
To explain why the error occurred, the meaning of the ? in a regex is to make the previous character or capturing group optional, which is why the pattern gives an error when the ? is the first character.
1
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.