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
Post a Comment