【发布时间】:2022-01-07 08:28:42
【问题描述】:
我正在尝试检测以下模式中的字符串:[url('example')] 以替换该值。
我曾想过使用正则表达式来获取方括号内的字符串,然后使用另一个来获取括号内的文本,但我不确定这是否是最好的方法。
//detect all strings inside brackets
preg_match_all("/\[([^\]]*)\]/", $text, $matches);
//loop though results to get the string inside the parenthesis
preg_match('#\((.*?)\)#', $match, $matches);
【问题讨论】:
-
试试这个:
(?<=\[url\(')[^']+(?='\)\])