Regex for nested XML attributes

后端 未结 2 591
情话喂你
情话喂你 2021-01-28 21:15

Lets say I have following string:

\"sop} z={ ABC }> }>\"<

2条回答
  •  误落风尘
    2021-01-28 21:41

    You're trying to deal with balanced set of braces. This requires recursive regular expressions. By definition, recursive regexes are not regular. Anyway, some languages support them, e.g. Perl, PHP, ruby. This is a good tutorial on the topic.

    Generally, you should extract this kind of information with a fully-fledged parser, like yacc.

    This is a regex that can deal with the non-balanced braces: ([ =]*)=(\{[^}]*\}). This will match {

    sop
    } and {st} which is correct. Unfortunately, it will match { too, which is not quite what you want.

提交回复
热议问题