Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ColdFusion Rereplace

Posted on 2016-08-17
3
Medium Priority
?
137 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Strategic internal linking is often considered an SEO power technique, especially for content marketing. Do you need to hire an SEO agency to optimize you internal linking? No, this article will help you understand the basics of internal linking and…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

810 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