Hi Anthony,
I think my reg exp does parse all what you say. Output only 4 numbers doesn't seem to me appropriated, I prefer getting seperated datas, and then, if needed, concatenate the necessary values.
However, I change my reg exp to have all numbers directly (with the sign if present, real numbers are matched too).
I made a second change : it is now possible to have directly the {size} and the {offset} in the output array.
Code: Select all
function im_geom($geom)
{
// the regex
$signe = "[\-|\+]";
$number = "\d*(?:\.\d+)?"; // an unsigned real ( 4, 3.2, -5 MATCH), (4. NOT MATCH)
$type = "[\%|\^|\!|\>|\<|\@]"; // different "types" : % ^ ! > < @ or "nothing". Have I forgot one ?
$size = "(?:($number?)($type?))?(?:x($number?)($type?))?";
$offset = "($signe{1}$number)?($signe{1}$number)?";
$regexp = "($size)($offset)";
preg_match("#$regexp#", $geom, $res);
return $res;
}
This function returns for 400x300+35-10 :
Array
(
[0] => 400x300+35-10
[1] => 400x300
[2] => 400
[3] =>
[4] => 300
[5] =>
[6] => +35-10
[7] => +35
[8] => -10
)
array[0] = the "full path"
array[1] = the {size} path
array[2] = width
array[3] = special char for width (! ^ < > @ if present)
array[4] = height
array[5] = special char for height (! ^ < > @ if present)
array[6] = the {offset} path
array[7] = "x" offset
array[8] = "y" offset
You can have a look on this page :
http://cedk06.free.fr/forumIM/test.php5 . There's a form to test the regexp, and a loop to see many (all ?) possibilities.
CedK