Creating a regex for parsing screens resolutions
I have a 开发者_如何转开发string of text that somewhere will contain the resolution to my vid in the format ###x###
or ####x####
(ex. 320x240 or ex. 1024x1280 ex. 320x1024 etc.) or any combo in between. I am not great at regexes yet and I was wondering if anyone could point out where I am going wrong.
$res='some long string';
$search='/([0-9]{3-4})x([0-9]{3-4})/';
preg_match($search, $res, $matches);
$res1=$matches[1];
$res2=$matches[2];
It should be:
$search='/([0-9]{3,4})x([0-9]{3,4})/';
You can also use:
$search='/([1-9]\d{2,3})x([1-9]\d{2,3})/';
(more specific)
精彩评论