I’m using reReplace to strip special characters from filenames. The following regex throws exceptions (see below) in my code. However, when I test the regex string in a ColdFusion Regex Utility it works just fine.
Here is my code:
reReplace(tmpName,"[{}\(\)\^$&%#!@=<>:;,~`'\'\*\?\/\+\|\[\\\\]|\]|\-",'','all')
And the error:
Error Messages: Invalid token @ found on line 29 at column 45.
The CFML compiler was processing:
An expression beginning with !, on line 29, column 44.This message is usually caused by a problem in the expressions structure.
If I escape the @ symbol with \@ I get this error:
Error Type: Template : [N/A] Error Messages: Invalid CFML construct
found on line 29 at column 45. ColdFusion was looking at the following
text:\\
The CFML compiler was processing:An expression beginning with !, on line 29, column 44.This message is usually caused by a problem in the expressions structure.
My original source for this regex string is: Regex to Strip Special Characters
I removed the . and _ as these characters should be allowed.
Because you have an unescaped
#in the middle of the regex.Bear in mind that
#has special meaning in CFML, so if you want to use a literal#, you need to escape it as##.So your regex should be: