Solved

Coldfusion regular expression not working as intended.!

Posted on 2011-03-11
13
433 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
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…

820 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