?
Solved

Coldfusion regular expression not working as intended.!

Posted on 2011-03-11
13
Medium Priority
?
440 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 1000 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 1000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
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…
Suggested Courses

621 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