正则表达式找到内容问题

尝试使用正则表达式refind标记在此示例中使用coldfusion查找括号内的内容
joe smith <joesmith@domain.com>

结果文本应该是

joesmith@domain.com

用这个

<cfset reg = refind(
 "/(?<=\<).*?(?=\>)/s","Joe <joe@domain.com>") />

没有运气.有什么建议?

也许是语法问题,它适用于我使用的在线正则表达式测试程序.

你不能在CF的正则表达式引擎中使用lookbehind(使用 Apache Jakarta ORO).

但是,您可以使用Java’s regex,它确实支持它们,并且我已经创建了一个包装器CFC,使这更容易.可从:
http://www.hybridchill.com/projects/jre-utils.html

(更新:上面提到的封装器CFC已演变成一个完整的项目.有关详细信息,请参阅cfregex.net.)

此外,/…/s内容在此处不是必需/相关的.

所以,从你的例子,但改进的正则表达式:

<cfset jrex = createObject('component','jre-utils').init()/>

<cfset reg = jrex.match( "(?<=<)[^<>]+(?=>)","Joe <joe@domain.com>" ) />

快速说明,因为我已经更新了几次正则表达式;希望它现在处于最佳状态……

(?<=<) # positive lookbehind - start matching at `<` but don't capture it.
[^<>]+ # any char except  `<` or `>`,the `+` meaning one-or-more greedy.
(?=>)  # positive lookahead - only succeed if there's a `>` but don't capture it.

相关文章

jquery.validate使用攻略(表单校验) 目录 jquery.validate...
/\s+/g和/\s/g的区别 正则表达式/\s+/g...
自整理几个jquery.Validate验证正则: 1. 只能输入数字和字母...
this.optional(element)的用法 this.optional(element)是jqu...
jQuery.validate 表单动态验证 实际上jQuery.validate提供了...
自定义验证之这能输入数字(包括小数 负数 ) &lt;script ...