[H-GEN] REGEX pattern required

Gary Curtis gazilla at gmail.com
Wed Dec 8 06:14:02 EST 2004


And the winner is...

preg_match('/^(.*?)(\d+)(\D*)$/',$mystr,$matches);

...which is basically Byron's pattern with the [0-9] and [^0-9]
replaced with \d and \D respectively.

I have hit this with all sorts of strings and consistently get
the result I desired.   Output of print_r($matches) using an
input string of 'abc999def123rst' is...

Array
(
    [0] => abc999def123rst
    [1] => abc999def
    [2] => 123
    [3] => rst
)

Thanks to all who participated.

Gaz
-- 
---------------------------------------------------------------------------------------------------
And remember, it's spelled Gary Curtis, but it's pronounced "Gazilla"




More information about the General mailing list