php preg_match returns only matched portion of string when I am certain that there is an unmatched portion too
so I am trying to get all unmatched text, and I have code snippets that look like: Row, Col = (1, 1) Row, Col = (1, 2) Row, Col = (9999999, 9999999) stored in an array called $foo my preg开发者_如何学编程_match statement looks like:
foreach($foo as $fooPartition){
if(preg_match("/.*\([0-9]+\, /", $fooPartition, $match)){
$unecessaryFluff = $match[0];
$infoINeed = $match[1];
}
}
I keep on getting back $unecessaryFluff but I get a missing index when I try to access $match[1], and my debugger verifies that $match is in fact just a length 1 array containing the matched portion of the string, and $match[1] DNE.
Does anyone know What I am doing wrong that is making the preg_match not return the unmatched portion of the string per the php page specs? (using php 5.3.2)
You need to specify grouped expressions (using parentheses) if you want to isolate specific strings.
For example, say you just wanted the digits
/.*\(([0-9]+)\, /
Not sure why you're escaping the comma, is that a typo?
精彩评论