我需要一个简单的PHP正则表达式的帮助来匹配一系列括号和它们内部的任何字符[关闭]

I can't seem to figure this simple thing out.

basically I have entries like:

Bree@email.com (Bree Olsen)
(Daisy Marie) +015487572
etc

I need to use just the actual address or phone number. Hence I need to delete the (any)part of the strings.

Please advise

$parenthesesContentRemoved = preg_replace('/\(.*\)/', '', $content);

This should do the trick..

Or.. $parenthesesContentRemoved = preg_replace('/\s?\(.*\)\s?/', '', $content);

Which should also remove the spaces around the parentheses.

/^(.*)\([^)]*\)(.*)$/$1$2/

Explained:

  • ^ Anchor to beginning,
  • (.*) any series of characters in group 1
  • an opening bracket (
  • any series of characters except a closing bracket [^)]*
  • a closing bracket
  • any series of characters in group 2