Solved

Coldfusion regular expression not working as intended.!

Posted on 2011-03-11
13
431 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 74

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
@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
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
@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
Comment Utility
And if that doesn't work, then try this:

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

Open in new window

0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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
Comment Utility
@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 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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
Comment Utility
Yup that solved it. Thanks!
0
 
LVL 74

Expert Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

by Batuhan Cetin Regular expression is a language that we use to edit a string or retrieve sub-strings that meets specific rules from a text. A regular expression can be applied to a set of string variables. There are many RegEx engines for u…
The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
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…

771 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

10 Experts available now in Live!

Get 1:1 Help Now