您不能将lookaground放入字符集中
[]
,请尝试使用OR条件将它们分成两种不同的情况:
<ref name="?((?:[^">\/]|\/(?!>))*?)"? *\/?>
<ref\sname="? # start of the ref tag, up to the name attribute
( # group 1, what you want to capture
(?: # non-capturing group, for grouping the following OR condition
[^">\/] # any character but `">/`
| # OR
\/(?!>) # if it IS a `/`, then it must NOT be followed by a `>`
)*? # this non-capturing group repeats 0 to unlimited times, as few as possible (to avoid capturing trailing whitespaces)
) # group 1 ends
"?\s*\/?> # everything after the name attribute
在此处检查测试用例。
但请注意,使用正则表达式匹配 HTML 标签通常被认为是