Reputation: 1345
I am parsing email content for Handlebars.Net
. Use case is like so:
string template = "{{I should be found}} but {{{I shouldn't}}}";
I think I need to use some combination of lookaheads and lookbehinds to find these tags but I cannot get this to work. I've created a regex which is close to what I need but is not matching exactly like how I need to - [^{]({{.*}})(!?})
Any ideas?
Upvotes: 3
Views: 191
Reputation: 785541
You can use this regex with a negative lookaround assertions:
(?<!{){{[^{}]+}}(?!})
(?!})
is a negative lookahead assertion that fails the match if next character is }
(?<!{)
is a negative lookbehind assertion that fails the match if previous character is {
Upvotes: 4