Link to home
Create AccountLog in
Avatar of erikTsomik
erikTsomikFlag for United States of America

asked on

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")#
Avatar of _agx_
_agx_
Flag of United States of America image

The "?" is a special character in regex's and needs to be escaped:

       reReplaceNoCase(cookie.lastpage, "\?target=(top|bottom)", "","ALL")
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.
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account