我有这种类型的字符串:
some text that can contains anything ((12.1,5.2))another text that can contains anything ((1,8.7)) and so on...
事实上我不知道如何获取:
[0] some text that can contains anything ((12.1,5.2))
[1] another text that can contains anything ((1,8.7))
...
我尝试过: preg_match_all('#(.*\(\([0-9\.]+,[0-9\.]+\)\).*?)#',$lines ,$match);
但肯定它不起作用。
我还尝试添加“U”选项和?在 * 和 + 之后,但没有更多结果。
谢谢
最佳答案
尝试使用您所拥有的这种变体:
preg_match_all('#.*?\(\([0-9.]+,[0-9.]+\)\)#',$lines,$match);
开头附近添加的问号很重要,否则点也会消耗左括号。我还删除了右括号后面的部分,假设您的下一行从那里开始。
此外,您不需要整个捕获组。
以下内容
if ($match !== false) {
var_export ($match[0]);
}
将输出:
array (
0 => 'some text that can contains anything ((12.1,5.2))',
1 => 'another text that can contains anything ((1,8.7))',
)
关于php - 正则表达式获取 "any_characters((number,number))",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35418208/