replace all “foo” between ()

后端 未结 3 1932
甜味超标
甜味超标 2020-12-11 22:15

I\'ve problem with my regex code, the problem is: I want to replace all \"foo\" values but only inside \"()\". Example:

try foo foo-foo (try foo inside , foo         


        
3条回答
  •  旧巷少年郎
    2020-12-11 22:57

    If you can live with using a loop and replacing multiple times, this solution will work:

    do {
      $string = preg_replace('/(\([^)]*)foo([^)]*\))/U', '\1boo\2', $string, -1, $count);
    }while($count != 0);
    echo $string;
    

提交回复
热议问题