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

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -