preg_replace multiple strings between brackets (php/regex) -
i have string
[test](test\\-test\\-abc) abcde\\-
i have
[test](test-test-abc) abcde\\-
i need replace \\-
-
regex/preg_replace. need replace string between parenthesis. found solution replaces first occurance.
$result = preg_replace("/(\[.*?\])(\(.*?)(\\\\-)(.*?\))/", '$1$2-$4', $str);
you can use preg_replace_callback
:
$str = '[test](test\\\\-test\\\\-abc) abcde\\\\-'; $txt = preg_replace_callback('~\([^)]+\)~', function ($m) { return str_replace('\\\\-', '-', $m[0]); }, $str); echo $txt; //=> [test](test-test-abc) abcde\\-
Comments
Post a Comment