[H-GEN] REGEX pattern required
Gary Curtis
gazilla at gmail.com
Wed Dec 8 00:40:14 EST 2004
On 08 Dec 2004 13:58:01 +1000, Russell Stuart
<russell-humbug at stuart.id.au> wrote:
>
> On Wed, 2004-12-08 at 13:42, Byron Ellacott wrote:
> > The three groups are (.*?), ([0-9]+) and ([^0-9]*). The first matches
> > as few characters as necessary to pad the expression out -- the ?
> > modifier makes the * modifier non-greedy. The second matches one or
> > more digits. The third expression requires that everything after the
> > digit sequence be non-digits, that is, the digit sequence must match the
> > right-most digit sequence.
> >
> > If you're using a different regex engine, you will need this adjusted to
> > suit.
>
> And just to refine it a bit further, the regex above will sort
> of work with PHP's preg_match(), where "sort of" means the array
> returned will have 4 elements - not the three Gary asked for.
> But its probably close enough - just ignore the first element.
This would not be a problem so long as the digits are always
in [say] the third element AND elements one and two, together,
represent the section of the string to the left of the digits.
> Gary's question originally asked for a regex to feed to
> preg_split(). There is no regex you can pass to preg_split()
> that returns what Gary wanted.
Gaz
--
---------------------------------------------------------------------------------------------------
And remember, it's spelled Gary Curtis, but it's pronounced "Gazilla"
More information about the General
mailing list