开发者

Regex, exclude certain character

I am trying to build a regular expression. However I get stuck and can't find the solution :(. Please help.

I want to get the string contains {\d} that are not preceed by \.

Example:

abc{1}def{2} ghi{3} jkl{4}{5}mno \{6}ofg\{7}{8}.

The result would be :

{1} {2} {3} {4} {5} and {8}.

Any 开发者_如何学运维idea to build regex for it?

Thank you


You can use the regex:

(?<!\\)(\{\d\})


(?<!\\){\d}

This will match only the portions you want.


You use a caret after the left square bracket to negate a character class.

I.e. [^\\](\{\d\})

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜