Solved

ColdFusion Rereplace

Posted on 2016-08-17
3
62 Views
Last Modified: 2016-08-22
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")#
0
Comment
Question by:erikTsomik
  • 2
3 Comments
 
LVL 52

Expert Comment

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

       reReplaceNoCase(cookie.lastpage, "\?target=(top|bottom)", "","ALL")
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 41760789
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
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 41760965
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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now