Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 139923

Matching dollar literally but only if not escaped [duplicate]

$
0
0

so I have a string like hello $1 and another string hello \$1 I want to use a regex test to check if the dollar has a backslash behind or not. If it has one then test must evaluate to false and if it doesn't have one behind then it must evaluate to true. example:

let string1 = "hello $1";
/regex/.test(string1); //-> returns true

let string2 = "hello \$1";
/regex/.test(string1); //-> returns false

I already tried this /[^\\$]\$[1-3]{1}/.test(string) but it doesn't work. Thanks in advance


Viewing all articles
Browse latest Browse all 139923

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>