It works for most of the case, but not for mixed quotes:
'const a = "Hi, I\'m Anthony"'.match(/['"`](.*)['"`]/m) // "Hi, I"
You have to make sure the starting quote and ending quote are the same type. Initially I thought it was impossible to do it in RegExp, or we have to do like this:
That’s definitely a bad idea as it makes you duplicated your notations. Until I found this solution:
\1 is a Backreferences to your first group, similarly you can have
\2 for the second group 2 and
\3 for the third, you got the idea. This is exactly what I need! Take it a bit further, to exclude the backslash escaping, now we can have a much reliable RegExp for extracting quoted texts from any code.
You can find it running in action on my