Matching data from file with regex

試著忘記壹切 提交于 2020-01-04 14:00:45

问题


The file I am pulling the data from consists of the following information

<"DATA" 10.21                         
^"DATA" 81.39                         
_"DATA" 38.71                         
"DATA" 84.19                          

Using preg_match, how can I pull the values from each?

I tried $r = '/<"DATA" (.+?)/'; but it didn't give me the numbers.

Anyone know the correct regex to pull these numbers?

Thanks in advance!


回答1:


preg_match_all('/^\s*.?"DATA" (\d+)\.(\d+)\s*$/m', $str, $matches);

CodePad.




回答2:


You have to use the preg_match_all function:

preg_match_all('/^[<^_ ]"DATA" (\d+\.\d+)$/m', $string, $matches);
// look in $matches


来源:https://stackoverflow.com/questions/7076684/matching-data-from-file-with-regex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!