php: regex remove bracket in string

前端 未结 4 2058
醉话见心
醉话见心 2021-01-22 05:16

similiar like this example, php: remove brackets/contents from a string? i have no idea to replace

$str = \'(ABC)some text\'

into



        
4条回答
  •  甜味超标
    2021-01-22 06:06

    If you want to use replace, you could use the following:

     $str = "(ABC)some text";
     $str = preg_replace("/^.*\(([^)]*)\).*$/", '$1', $str);
    

    The pattern will match the whole string, and replace it with whatever it found inside the parenthesis

提交回复
热议问题