为什么ColdFusion会在正则表达式上抛出错误来删除特殊字符?

ete*_*rps 1 regex coldfusion coldfusion-9

我正在使用reReplace从文件名中删除特殊字符.以下正则表达式在我的代码中抛出异常(见下文).但是,当我在ColdFusion Regex实用程序中测试正则表达式字符串时,它可以正常工作.

这是我的代码:

reReplace(tmpName,"[{}\(\)\^$&%#!@=<>:;,~`'\'\*\?\/\+\|\[\\\\]|\]|\-",'','all')
Run Code Online (Sandbox Code Playgroud)

而错误:

错误消息:第45行第29行找到无效的令牌@.

CFML编译器正在处理:

An expression beginning with !, on line 29, column 44.This message is usually caused by a problem in the expressions structure.
Run Code Online (Sandbox Code Playgroud)

如果我逃避@符号,\@我得到这个错误:

错误类型:模板:[N/A]错误消息:在柱45的ColdFusion一直在寻找在以下文本上线29找到无效CFML构建体:

\\ CFML编译器正在处理:

An expression beginning with !, on line 29, column 44.This message is usually caused by a problem in the expressions structure.
Run Code Online (Sandbox Code Playgroud)

这个正则表达式字符串的原始来源是:正则表达式去除特殊字符

我删除了.,_因为这些字符应该被允许.

Ada*_*ron 5

因为你#在正则表达式的中间没有转义.

请记住,#它在CFML 中具有特殊含义,因此如果要使用文字#,则需要将其转义为##.

所以你的正则表达式应该是:

[{}\(\)\^$&%##!@=<>:;,~`'\'\*\?\/\+\|\[\\\\]|\]|\-
Run Code Online (Sandbox Code Playgroud)