preg_match一个String,用于从字符串中获取某些数字
I have a string that always has the following format
Text: 1.1111111 Text
What I need is 1.11
of the string
So I went with this regex
^(\S*\s)(\d.\d{2})
I've used http://regex101.com/ to try it out and it works there, but when I do it on my own code, the matches array is always empty.
This is the code
//$ratingString = Durchschnittsbewertung: 4.65000 von 5 Sternen 20 Bewertungen Location bewerten
preg_match ( "/^(\S*\s)(\d.\d{2})/", $ratingString, $matches );
var_dump ( $matches );
// matches == array (0) {}
我的字符串总是具有以下格式 p>
我需要的是 所以我选了这个 正则表达式 p>
^(\ S * \ S)(\ d \ d {2})代码> p>
I” 使用 http://regex101.com/ 进行试用,它可以在那里工作,但当我在我的 自己的代码,matches数组总是空的。 p>
这是代码 p>
文字:1.1111111文字 code> p>
1.11 code>的字符串 p>
// $ ratingString = Durchschnittsbewertung:4.65000 von 5 Sternen 20 Bewertungen位置bewerten
preg_match(“/ ^(\ S* \ s)(\\\
d {2})/”,$ ratingString,$ matches);
var_dump($ matches);
// matches = = array(0){}
code> pre>
div>
You need to escape the dot as dot is special character in regex which matches any character if not escaped:
^(\S*\s)(\d\.\d{2})
god, so here...sorry for editing. like this
$ratingString = "Durchschnittsbewertung: 4.65000 von 5 Sternen 20 Bewertungen Location bewerten";
preg_match ( "#(\d\.\d{2})#", $ratingString, $matches );
var_dump ( $matches );