[英]Regex: Match all brackets {} that are not in expressions {0} or {1}
The title says all, I am trying to match all {
and }
but not those included in {0}
or {1}
. 标题说明了所有问题,我正在尝试匹配所有{
和}
但不匹配{0}
或{1}
。
Ex: {asd } {2} asds}w2{1}
例如: {asd } {2} asds}w2{1}
Here, all brackets would match but the last 2. 在这里,所有括号都将匹配,但最后一个是2。
Edited based on comments: 根据评论进行编辑:
Here you go: 干得好:
(?!\{[01]\})\{|(?<!\{[01])\}
Explanation: 说明:
{
if what follows is not {0}
or {1}
. 如果后面不是{0}
或{1}
则匹配{
。 }
if what precedes is not {0
or {1
. 如果前面不是{0
或{1
则匹配}
。 The matches in the following sample are bolded: 以下示例中的匹配项以粗体显示:
{ asd } { 2 } asds } w2{1} { foo } {0} { bar } } { { } { asd } { 2 } asds } w2 {1} { foo } {0} { bar } } { { }
You can use negative lookhead based regex : 您可以使用基于负号的正则表达式 :
\{(?![12]\})[^}]*\}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.