have this string:
$var = "30.5x120.8 (test desc here)";
I need to get out 30.5 and 120.8 with a regular expression.. any help?? Thx
have this string:
$var = "30.5x120.8 (test desc here)";
I need to get out 30.5 and 120.8 with a regular expression.. any help?? Thx
preg_match_all('~\d+(?:\.\d+)?~', $string, $matches);
var_dump($matches[0]);
30.5x.2? Is that a thing you want to support?$string = preg_replace('(?<!\d)\.\d+', '0$0', $string); before you run the code above.$var = "30x120 (test desc here)";
preg_match_all('/^(\d+)x(\d+)/', $var, $matches);
var_dump($matches)
array(3) {
[0]=>
array(1) {
[0]=>
string(6) "30x120"
}
[1]=>
array(1) {
[0]=>
string(2) "30"
}
[2]=>
array(1) {
[0]=>
string(3) "120"
}
}
also work for 17.5x17.5 ?
Here is one which will...
/^(\d+(?:\.\d+)?)x(\d+(?:\.\d+)?)/
preg_match() would make more sense (and make the output array easier to parse) than preg_match_all() as there's only one occurence of the pattern in the subject string.preg_match('/^(\d+)x(\d+)/', '30x120 (test desc here)', $result);
and use $result[1] and $result[2]