roger v
asked on
Coldfusion regular expression not working as intended.!
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?
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#">
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@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:
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"))>
<cfset badVal = "Inchon (Inch'on) (Incheon)">
<cfset goodVal = trim(ReReplace(badVal,"'","","all"))>
<cfdump var="#badVal#">
<br />
<cfdump var="#goodVal#">
untitled.PNG
And if that doesn't work, then try this:
<cfset goodVal = trim(REReplace(badVal,"\'","","all")>
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.
The top code section is for the last comment. The bottom code section and screenshot apply to me testing your existing code.
Single quote isn't a special character in regex, sjklein42; it does not need to be escaped.
ASKER
@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 - ( )
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 - ( )
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"))>
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.
Better yet... Just copy the character from a dump of that column... then paste it into the patter : )
ASKER
Yup that solved it. Thanks!
NP. Glad to help : )
ASKER
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?