在 ReReplace 函数中调用函数
有没有办法在 Coldfusion 中写类似:
< cfset ReReplace(value,"&#\d+;","#decodeHtmlEntity(\1)#", "all") >
非常感谢
Is there a way to write in coldfusion something like:
< cfset ReReplace(value,"\d+;","#decodeHtmlEntity(\1)#", "all") >
Thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
简短的回答是“否”。
CF 本身不处理正则表达式执行。它交给 Java 库(Oro、IIRC)来处理。这意味着您调用的任何 CF 函数都会在正则表达式之前执行。
有一个解决方法,尽管它不像能够传递函数那么优雅。使用 reFind() 来发现您要查找的所有实例,并一一重新定位它们。如果您从最后到第一个进行替换(例如,如果有 3 个实例,则执行第 3 个,然后是第 2 个,然后是第 1 个),每场比赛的起点将保持在同一位置,因此您可以重新查找所有,而不是在循环中进行重新查找。
HTH。
The short answer is "No".
CF doesn't handle the regular expression execution natively. It hands off to a Java library (Oro, IIRC) to handle that. This means that any CF functions you call get executed before toe regex.
There is a workaround, although it's not nearly as elegant as being able to pass functions would be. Use reFind() to discover all the instances of what you are looking for, and repolace them one-by-one. If you do the replaces last-to-first (eg if there are 3 instances, do the 3rd, then the 2nd, then the 1st) your starting point for each match will remain in the same location, so you can do an reFind all, instead of doing the reFind in the loop.
HTH.
如果您想将正则表达式值替换为decodeHTMLEntity 的参数,我认为这不起作用。
更新:
上面的代码是为了从文本中查找 123 并在其中添加 1 而编写的,但这不起作用,因为 arg1 将具有 \1,它不是数值。
I don't think this will work if you want to replace regular expression value as argument of decodeHTMLEntity.
Updated:
Above code written to find 123 from text and add one into it but this will not work as arg1 will have \1 which is not numeric value.
您是否尝试过简单地使用 URLDecode(value) ?
或者,如果您特别只想解码数字 html 代码,那么
将执行您需要的操作。
为了解释它在做什么:
Have you tried simply using URLDecode(value)?
Or if you specifically only want to decode the numeric html codes, then
will do what you need.
To explain what it is doing :