Reputation: 171
I need help with regex. I have to match "{{" at the beginning of the string but not "{{{". I tried to use ^[{]{2}
but it matches for "{{{". I tried to match "{{{" with ^[^{]{3}
but I don't know how to match "{{" again.
I know I can probably get around it with a if statement. But I would like to do it in one shot within regex. Any Idea?
Upvotes: 0
Views: 231
Reputation:
Use negative lookahead:
const re = /^{{(?!{)/;
console.log("{{{".match(re));
console.log("{{a".match(re));
Upvotes: 1