嘿,我正在尝试将所选内容完全放入数组中,但它无效。这就是我所拥有的:
$stripped = "listing requirements. $ 669,647,431,200 P/E Ratio: 17.75 Forward P/E(1y) A widel";
$pattern = '/P\/E+\s+\w\w\w\w\w\W\s\w\w\W\w\w/';
preg_match($pattern, $subject, $matches);
print_r ($matches);
基本上我希望它只是将“P / E Ratio:17.75”输出到一个数组中。没别了。
如果P / E说114.13,我意识到我的表格也行不通。我怎么能让它选择接下来的两个“单词”?
谢谢!
答案 0 :(得分:1)
您可以将正则表达式简化为
P\/E Ratio: [\d.]+
示例:http://regex101.com/r/tK9rR0/1
$subject = "listing requirements. $ 669,647,431,200 P/E Ratio: 17.75 Forward P/E(1y) A widel";
$pattern = '/P\/E Ratio: [\d.]+/';
preg_match($pattern, $subject, $matches);
print_r ($matches);
将提供输出
Array ( [0] => P/E Ratio: 17.75 )