If you have this character, discard the catch

0

How do I make regular expression not capture what has \} in text? I want you to get all } , but I want it to be escaped with the \ character be discarded, not ignored.

I am trying this expression: [^\]} but it returns a character before } ...

Summary: If you have the \ character before }, discard the catch.

    
asked by anonymous 15.11.2015 / 22:06

1 answer

2

In the comment of @ ViníciusGobboA.deOliveira a negative lookbehind assertion (?<! subexpression) to check the previous character. The syntax in PCRE and .NET is the same.

(?<!\)(\})

It means: Capture a bracket only if there is no backslash before.

Important, groups started with (? are not counted, so the group (\}) will have index 1.

    
16.11.2015 / 14:29