$string = 'ab12345-1';
if (preg_match('/^([a-zåäö]{2,3})([0-9]{4,5}(\-[0-9]{1,2}){0,1})$/i',
$string,
$m='')) {
   echo $m[1]; // -> ab
   echo $m[2]; // -> 12345-1
}

g. martin luethi


Tue, 20 Jan 2004 09:59:37 +0100 Victor Spång Arthursson <[EMAIL PROTECTED]>:

> Hi!
>
> Anyone who could help me with this regexp problem?
>
> I want to verify that a string is made up of 2-3 letters, (a-z + åäö,
> A-Z + ÅÖÄ), directly followed by 4 or 5 digits, which could, but may
> not, be followed by a minus and one or two digits.
>
> Examples of valid strings:
>
> abc12345
> ABC12345
> abc1234
> ABC12345-1
> ABC12345-01
>
> I would also like to split them into an array consisting of 2 elements;
>
> [0] = the first 2 or 3 letters
> [1] = the rest
>
> Example:
>
> string = ab12345
> [0] = ab
> [1] = 12345
>
> string = åäö1234-66
> [0] = åäö
> [1] = 1234-66
>
> Lots of thanks in advance,
>
> sincerely
>
> Victor
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to