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\})
精彩评论