从字符串逗号和括号中删除内容

Remove contents from a string comma and bracket

我想根据我的要求过滤一个字符串

$string="my super city (name , result)";

我只想 result 作为输出。

有专家吗???

如有任何帮助,我们将不胜感激。

试试这个

$full = preg_replace("/[^A-Za-z ]/", '', $string);

如果您还需要数字 (0-9),请尝试

$full = preg_replace("/[^A-Za-z0-9 ]/", '', $string);

编辑:

然后

 $exp = explode(" ", $full);
 echo $exp[count($exp)-1];

执行替换:

$result = preg_replace( '/.*?,\s*(\w+)\).*?/', '', $string );

$result 你有这个:

result

如果要匹配 每个 个非逗号字符,请改用此正则表达式:

/.*?,\s*([^,]+)\).*?/

第一个模式解释:

/
.*?     zero-or-more characters
,       a comma
\s*     zero-or-more spaces
(\w+)   Group 1: one-or-more word characters
\)      closing bracket
.*?     zero-or-more characters
/

regex101 demo