Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有类似.com 注册 (domain.com)或xl 托管 (domain.com)之类的文本
我只想获得 Smarty 括号内的域。
我怎样才能做到这一点?
这对我有用:
{$preg = preg_match("/\(([^)]*)\)/", $o.title, $results)} {$results[1]}
您可以使用以下正则表达式:
/(\([^)]+\))/g
编辑:在前面的表达式中,括号内的域或任何内容都被捕获在组 1 中,因此您可以访问该组中匹配的内容。
正则表达式 101 演示
如果您需要替换除括号内的内容之外的所有内容,则可以使用以下表达式:
\G[^(]*(\([^)]+\))