Solved

ColdFusion Rereplace

Posted on 2016-08-17
3
71 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Element alignment and word wrapping 9 62
Where do I learn ES6? 3 50
app server have enough resources... 2 24
Standard for Web Development 3 27
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
This video teaches users how to migrate an existing Wordpress website to a new domain.
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).

895 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

18 Experts available now in Live!

Get 1:1 Help Now