php - Delete All Between ( and ) -


i want replace between ( , ). , works preg_replace().

$return =  preg_replace("/\([^)]+\)/", "", $return); 

if $return "hello name frank (nicer guy)"

the string "hello name frank"

but in case between parentheses next parentheses not work. example:

before:

"hello name frank (nicer (guy) thank you)"

after

"hello name frank thank you)"

it stops after first ")". possible deletes parentheses inside parentheses?

match beginning first ( , backtrack last occurrence of ):

\(.*\) 

note: * must greedy work. make sure ungreedy modifier u not set (default).


if strings can contain multiple occurrences of independent parenthesized substrings, i.e. "hello (my name is) frank (nicer (guy) thank you)", need recursive pattern.

the example \(((?>[^()]+)|(?r))*\) there works quite well.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -