2

Currently, I am doing search and replace using this pattern: "(?<=\\{).+?(?=\\})". This finds everything inside curly brackets. (Courtesy of https://stackoverflow.com/a/8526268/1143917)

I use 'MatchEvaluator' with a delegate, so, when the input string is {this} is a {string}, the delegate receives this and string.

This is not good for me because I want to replace both the matches and the curly brackets.

How do I change my regex expression so the delegate will receive matches with the curly brackets included, i.e. {this} and {string}?

Community
  • 1
  • 1
Vlad
  • 2,475
  • 21
  • 32

1 Answers1

1

Remove the positve lookbehind and positive lookahead, and just use the brackets:

 "\\{[^\\}]+\\}"

I can't be sure about this because I've never used regular expressions with C++, but the principle is match {, plus all characters that are not }, plus }.

MikeM
  • 13,156
  • 2
  • 34
  • 47