Using JavaScript, I need a regex that matches any instance of @{this-format} in any string. My original regex was the following:
@{[a-z-]*}
However, I also need a way to "escape" those instances. I want it so that if you add an extra @, the match gets escaped, like @@{this}.
I originally used a negative lookbehind:
(?<!@)@{[a-z-]*}
And that would work just fine, except... lookbehinds are an ECMAScript2018 feature, only supported by Chrome.
I read some people suggesting the usage of a negated character set. So my little regex became this:
(?:^|[^@])@{[a-z-]*}
...which would have worked just as well, except it doesn't work if you put two of these together: @{foo}@{bar}
So, anyone knows how can I achieve this? Remember that these conditions need to be met:
- Find @{this} anywhere in a string
- Be able to escape like @@{this}
- Be able to put multiple adjacent, like @{these}@{two}
- Lookbehinds must not be used