【问题标题】:A problem with regex (non wanted end) [duplicate]正则表达式的问题(不需要的结尾)[重复]
【发布时间】:2011-11-22 02:58:43
【问题描述】:

我有以下模式:

(name|id)\s*=\s*('|")([a-zA-Z\-\_])+('|")

我必须得到所有属性 name="a"id="ab_c" 没有结构 name="a-element "id="a-element"(以 -element 结尾),我尝试过:

(name|id)\s*=\s*('|")([a-zA-Z\_][^-element])+('|")

但它不起作用,是什么错误??

【问题讨论】:

标签: php regex


【解决方案1】:

你想要negative look-arounds,像这样:

(name|id)\s*=\s*('|")([a-zA-Z\-_](?!-element))+('|")

(但请记住,您可能不应该手动解析 XML。)

【讨论】:

    猜你喜欢
    • 2020-01-23
    • 2016-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多