输入线是这样的(只是其中的一部分):
[[Text Text Text]][[text text text]]asdasdasdasda[[asdasdasdasd]]
我想要的是列出所有匹配项,其中文本包含在一对中[[
and ]]
。
我确实尝试了几种模式,但是当未关闭时,所有模式都会失败[[
or ]]
在输入行内。例如:
[[text[[text text TEXT text]]
另外,如果输入行中存在单个括号怎么办,例如:
[[text [text] text TEXT text]]
我使用的正则表达式模式是:
\[\[[^\[\[]*\]\]
\[\[(?:(?!\[\[|\]\]).)*\]\]
火柴[[<anything>]]
, where <anything>
可能不包含双括号,但包含其他内容。您可能需要设置DOTALL
正则表达式引擎的选项允许点匹配换行符。
它将匹配[[match [this] text]]
in
[[don't match this [[match [this] text]] don't match this]]
解释:
\[\[ # Match [[
(?: # Match...
(?! # (unless we're right at the start of
\[\[ # [[
| # or
\]\] # ]]
) # )
. # ...any character
)* # Repeat any number of times
\]\] # Match ]]
注意:它将匹配[[match [this]]
在文中[[match[this]]]
因为正则表达式无法计数。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)