I\'m trying to swap dumb quotes for their smart equivalent. So I want to turn Jane said \'How do we do this?\' \'I don\'t know\' replied Sam.
into Jane said ‘
$singlequotesPattern = "/'(.*?)'/";
Add a ?
to make the *
quantifier non-greedy. A greedy quantifier finds the longest match possible. A non-greedy one finds the shortest.
Greedy:
Jane said 'How do we do this?' 'I don’t know' replied Sam.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Non-greedy:
Jane said 'How do we do this?' 'I don’t know' replied Sam.
^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^