php - 简单的正则表达式问题 : How to find the first parentheses and get the content inside it?

标签 php regex

我是 PHP 正则表达式的新手。 我怎样才能用几段长的字符串找到第一个括号的内容。

我假设我必须使用 preg_match 函数

最佳答案

preg_match("/^.*?\(([^\)]+)\)/", $search_this_string, $matches, PREG_OFFSET_CAPTURE);
print_r($matches);

这假设您用括号括起来的字符串不包含任何转义的(以某种方式)右括号。

关于php - 简单的正则表达式问题 : How to find the first parentheses and get the content inside it?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1793414/

相关文章:

php - Apache 和 PHP 的问题 [ubuntu]

php - 无法在 Laravel 中复制 DATE_FORMAT 查询

php - 如何在php中格式化时间

c# - 通过 C# 将破折号分隔的字符串转换为驼峰式大小写

mysql - 使用正则表达式将一列拆分为多列

r - 如何用 R 在字符串中的最后一个斜杠后用 "_"替换空格

php - 在 curl php 中获取最后一个重定向的 url

php - $stmt->fetch() 未获取数据

regex - Notepad++ 删除除匹配正则表达式之外的所有文本

regex - Apache mod_rewrite 将双斜杠转换为一个斜杠