我正在尝试使用preg_match_all()
从以下行中提取日期和#之间的价格44,380.86。日期是2015年1月1日将是动态的,有人可以告诉我如何完成它吗? / p>
start on Jan 1, 2015 44,380.86 # of count: 15 tc
答案 0 :(得分:2)
您可以使用此正则表达式(regex explanation):
start on\s[A-Za-z]+\s[1-9]+,\s[0-9]+\s+(.*?)\s+#
示例代码:
<?php
preg_match_all(
"/start on\s[A-Za-z]+\s[1-9]+,\s[0-9]+\s+(.*?)\s+#/",
"start on Jan 1, 2015 44,380.86 # of count: 15 tc",
$matches
);
var_dump($matches);
答案 1 :(得分:0)
我认为这应该可以解决您的其他更改问题:
preg_match_all("(\S+(?:\s\S+)*?)","Your string",$matches);
对于您的问题,您可以使用:
preg_match_all("(\S+(?:\s\S+)*?)","start on Jan 1, 2015 44,380.86 # of count: 15 tc",$matches);
echo $matches[5];
此正则表达式使用空格来解析您的字符串,因此当您更改字符串时,只需将$matches
的索引从5
编辑到您想要的