-1

I know this has been asked before, but I just couldn't get mine to work. Using this example, Im trying to get the template variable but not if its used in some kind of tag.

{{ callMe() }}

<img src="{{ callMe() }}" />

Should match the first one, {{ callMe() }} but not the second. Ive been tinkering with negative lookahead, but not sure if i understand it. Here's my regex. Can anyone please have a look. Thanks.

(?!<.+\/?>)(({{.*([\w\.]+)\(.*\).*}}))

https://regex101.com/r/ZXU8RM/1

1 Answers1

0
(?<!<.*){{.*([\w\.]+)\(.*\).*}}(?!.*>)

Need to check there's no < before and no > after

(?<!<[^>]*){{.*([\w\.]+)\(.*\).*}}(?![^<]*>)

would also check for <p>{{ callMe() }}</p>

Thanos Dodd
  • 572
  • 1
  • 4
  • 14