开发者

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

开发者 https://www.devze.com 2023-01-25 08:16 出处:网络
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 \"]]\".

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

精彩评论

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