Match string to regex in javascript
3 answers
[^\\]?(".*?[^\\]")
You can try something like this. You will need to capture a group or capture and not match. See demo.
https://regex101.com/r/nS2lT4/30
or
(?:[^\\]|^)(".*?[^\\]")
See demo.
+1
source to share
In this case, you shouldn't use [^"]*
, and you don't need anyone-greedy, you can use the following regex to match everything between two quotes:
/"(.*)"/g
And if you want to match anything in between "
, you can just use the word character match with the space helper in the character class with the global modifier:
/[\w\s]+/g
Alternatively, you can use negative appearance :
/(?<!\\)"(.*?)(?<!\\)"/
0
source to share