I am trying to remove quotes from a string. Example:
"hello", how 'are "you" today'
returns
hello, how are "you" today
I am using php preg_replace.
At the moment, I have several solutions:
(\'|")(.*)\1
The problem with this is that all characters (including quotation marks) in the middle match, so the result ($ 2) is
hello", how 'are "you today'
Backlinks cannot be used in character classes, so I can't use something like
(\'|")([^\1\r\n]*)\1
not to match the first backlink in the middle.
The second solution:
(\'[^\']*\'|"[^"]*")
The problem is that this includes quotes in the backlink, so it actually does nothing. Result ($ 1):
"hello", how 'are "you" today'
source
share