加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式找到内容问题

发布时间:2020-12-13 22:53:34 所属栏目:百科 来源:网络整理
导读:尝试使用正则表达式refind标记在此示例中使用coldfusion查找括号内的内容 joe smith joesmith@domain.com 结果文本应该是 joesmith@domain.com 用这个 cfset reg = refind( "/(?=).*?(?=)/s","Joe joe@domain.com") / 没有运气.有什么建议? 也许是语法问
尝试使用正则表达式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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读