Solved

Coldfusion regular expression not working as intended.!

Posted on 2011-03-11
13
432 Views
Last Modified: 2012-06-21
Hi,

I'm having a really crazy issue - the coldfusion replacenocase function does not work! Neither does the ReReplace function. All I'm trying to do is replace a single quote " ' ", with a space. But the problem is that the single quote is inside a pair of parentheses, so coldfusion does not capture the single quote! How do I resolve this?
<!---the string that has the single quote inside parenthesis--->
<cfset badVal = "Inchon (Inch'on) (Incheon)">

<!---the regexp I'm using to get rid of the single quote, but won't work--->
<cfset goodVal = trim(ReReplace(badVal,"'","","all")>

<!---the dump shows that goodval still has the single quote with the parenthesis around it! --->
<cfdump var="#goodVal#">

Open in new window

0
Comment
Question by:roger_v
  • 8
  • 3
  • 2
13 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
ID: 35111564
Are you sure it's a single-quote and not one of those fancy quotes that *appear* to be single quotes?
0
 
LVL 16

Assisted Solution

by:sjklein42
sjklein42 earned 250 total points
ID: 35111637
It is REReplace, not ReReplace.  I think it may matter:

<cfset goodVal = trim(REReplace(badVal,"'","","all")>

Open in new window

0
 
LVL 1

Author Comment

by:roger_v
ID: 35111651
@kaufmed,

Good question. I'm not sure, that's how it's stored in the MSSQL db. Even if it is, could I look for single quote OR any funny character and strip it out?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35111726
@sjklein42

It didn't for my test   :  )


@roger_v

I tested your code and it seems to work for me. As for searching for single and "funny" chars, you can simply add them to your search criteria. For example:

<cfset goodVal = trim(ReReplace(badVal,"['´']","","all"))>

Open in new window

<cfset badVal = "Inchon (Inch'on) (Incheon)">

<cfset goodVal = trim(ReReplace(badVal,"'","","all"))>

<cfdump var="#badVal#">
<br />
<cfdump var="#goodVal#">

Open in new window

untitled.PNG
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 35111729
And if that doesn't work, then try this:

<cfset goodVal = trim(REReplace(badVal,"\'","","all")>

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35111737
I didn't do a very good job of organizing...    : (

The top code section is for the last comment. The bottom code section and screenshot apply to me testing your existing code.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35111750
Single quote isn't a special character in regex, sjklein42; it does not need to be escaped.
0
 
LVL 1

Author Comment

by:roger_v
ID: 35111791
@kaufmed & @sjklein,

I tried both of y'all's approaches - didn't work. Every other single quote is stripped out except for the one that is in between the parentheses - ( )
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35111895
I was just giving an example. It's most likely a straight apostrophe (I don't know the proper name). You'll probably have to search the unicode tables to find it. I've expanded my previous list below, but I don't know if I managed to capture it. Scan the unicode tables for anything that looks like an apostrophe and add it to the list below.
<cfset goodVal = trim(ReReplace(badVal,"['´'’¿‘''¿`´]","","all"))>

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35111909
The question marks are not part of the input. EE (or the browser) didn't like those characters, so those are placeholders. The intent of the above post remains the same, however.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35111928
Better yet...   Just copy the character from a dump of that column...  then paste it into the patter   :  )
0
 
LVL 1

Author Closing Comment

by:roger_v
ID: 35112416
Yup that solved it. Thanks!
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35112444
NP. Glad to help  : )
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

831 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