gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 08:44:47 24 4
gpt4 key购买 nike

我是 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com