-1

I need a regular expression that finds grave accents that surround a string, but not if that string contains ${ someVar }.

const twoMatch = `test string`;
const noMatches = `test ${ variabel }`;

This would be good to easily replace the grave accents with regular apostrophes.

Tim
  • 967
  • 12
  • 22
  • Neither `twoMatch` nor `noMatches` contain any. – evolutionxbox Nov 12 '20 at 21:11
  • Im not searching inside the string values, I want to use the IDE search to find the Grave accents surrounding, and thus defining it is a string value. – Tim Nov 12 '20 at 21:17
  • So you've opened the JS file as text and are searching through that? --- `'' === \`\` // true` – evolutionxbox Nov 12 '20 at 21:18
  • I'm opening the JS file (actually TS in this case) in Visual Studio Code. And using the search to find the grave accents. – Tim Nov 12 '20 at 21:20
  • 1
    Does this answer your question? [Reference - What does this regex mean?](https://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean) – evolutionxbox Nov 12 '20 at 21:23
  • Sure, it helps. But it requires me to do the thinking ;). Actually I'm working on it and when I have an answer I will of course share it here :). – Tim Nov 12 '20 at 21:28

1 Answers1

1

try this

(?<!.*\${.*)(\b\w+\b)(?!.*}.*)

explain :

(?<!.*\${.*) : not precided by '${' in any place
(?!.*}.*) : not followed by '}' in any place
\b : word boundry
\w+ : 1 or more character [a-zA-z0-9_]

demo

aziz k'h
  • 743
  • 2
  • 10
  • Looks very promising! I tried it in the IDE (Visual Studio Code) but it complains it is invalid "Incomplete quantifier". – Tim Nov 12 '20 at 21:45
  • But on the second look, it matches the string and not the grace accents. I'm far from confident this is possible with an regex. Might need some code. Like a linter rule. – Tim Nov 12 '20 at 21:50
  • 1
    In computing I think the term for \` is “back-tick” or “backquote” – evolutionxbox Nov 13 '20 at 01:30