开发者

RegEx: extract everything until X where X is not between two braces

I am looking for a regex, that extracts everything after a given text (here, "HIT") until the next pipe symbol "|" which is NOT surrounded by "[[" and "]]".

Example-Text:

text | HIT = [[t1|t2]] moretext [[more braces]] | moretext | moretext

This is the regex I've tried:

HIT[ \t]*=(.[^\|]+)

Of course, this only returns "HIT = [[t1" but I am looking for a regex that returns "HIT = [[t开发者_如何学C1|t2]] moretext [[more braces]]".

Thanks for your kind support

Christian


Try this regular expression:

HIT[ \t]*=((?:[^[|]|\[\[[^[\]]*]])*)

The (?:[^[|]|\[\[[^[\]]*]])* part matches

  • any sequence of either any character except [ and | ([^[|]), or
  • a sequence of any character except [ and ] that is surrounded by [[…]] (\[\[[^[\]]*]]).
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜