I would like to get a string between quotation marks
I know a solution that’s:
/'.*?'/
But the problem is that it doesn’t work with the possessive case or contraction case in English
for example:
What is the name of Mario's brother in the 'Super Mario' video games?
or
He's my brother
it can’t work with those sentences
One option would be to make sure that there is no word boundary before the opening and after the closing
':The position between a word character (usually letters, digits, underscores in regular expressions) and a non-word character (anything else or an end of the string) constitutes a word boundary (
\b). All other positions are matched by\B.Working demo.
Further reading on word boundaries.
By the way, if you want to allow double quotes, too, you can assure consistent delimiting with a backreference:
If you would just use
['"]twice, then something likehere "my' stringwould give you a match, which you probably don’t want. Note that depending on how you define your regex, you might need to escape one of the quotes.