Regex to match all the words that is not a interpolated string

Viewed 46

I want to match all the words except interpolated string i.e, strings which are inside #{...}

'The variable 1 is #{vf a sr} abc' 'the variable 2 is #{var}' 'the variable is something' 'The variables are #{ b } and #{&c&}'

I want to avoid matching all the strings in {..} , as well as if there is any space character or special symbols inside it.

I have written one regex : /(?<![#{\w])\w+(?![\w}])/gi. It has one negative lookbehind (?<![#{\w]) and one negative lookahead (?![\w}). The problem is its still matching the a in {vf a sr}. And the regex also breaks if there is a special character like {&c&}, in this case it now match the c.

https://regex101.com/r/lEieyw/5

0 Answers
Related