[thelist] Re: REGEX problem

Mike Boucher mike at xlr8studios.com
Fri Feb 27 19:46:54 CST 2004


Hi again,

Playing around with your regular expression a little more I find a small
loophole in it. As of now it will match what you are looking for but it will
also match CF-SDDS((*()*DS()(F((*SD( because the first half of the string
matches correctly it stops looking. It would match any string that had the
CF-KDJ in it actually. To force it to match only the patterns C-JFHJ and
CF-KDJ add a carat (^) at the beginning and a dollar sign ($) at the end.
This will tell it that this pattern starts at the beginning and should match
to the end of the string. Here is what your REGEX should look like.

if (ereg("^C-[A-Z]{4}|CF-[A-Z]{3}$",$_GET['s']))
{
 echo "matched";
}
else
{
 echo "no match";
}

Best of luck,
Mike Boucher
XLR8STUDIOS.com


----- Original Message -----
From: "Mike Boucher" <mike at xlr8studios.com>
To: <thelist at lists.evolt.org>
Sent: Friday, February 27, 2004 8:35 PM
Subject: RE: REGEX problem


> Hi Alexis,
>
> I'm on the digest version so I'm not sure if somebody already answered
this.
>
> I normal use the preg functions for pattern matching but this is pretty
much
> the same thing.
>
> With both preg and ereg the minus (-) is not considered a special
character
> unless used between a range (example: [A-Z]), therefor it does not require
> escaping. Just use it as is.
>
> I don't think your problem lies in the minus sign though. I just tested
your
> expression out and it works fine for me. Try using strtoupper() function
to
> make sure all your letters are uppercase. ereg() is case-sensitive so if
> there is a lower case letter it will return false. The other option is
using
> eregi() which is case-insensitive and will match both upper and lower
case.
>
> Hope this helps and good luck,
> Mike Boucher
> XLR8STUDIOS.com
>
>
>
>
> > Original Message
> > ------------------------------
> >
> > Date: Fri, 27 Feb 2004 16:34:12 -0400
> > From: The Lists <thelists at antonakis.co.uk>
> > To: "thelist at lists.evolt.org" <thelist at lists.evolt.org>
> > Subject: [thelist] REGEX problem
> > Message-ID: <403FA9C4.9050505 at antonakis.co.uk>
> > Content-Type: text/plain; charset=us-ascii; format=flowed
> > MIME-Version: 1.0
> > Content-Transfer-Encoding: 7bit
> > Precedence: list
> > Reply-To: thelists at antonakis.co.uk, "thelist at lists.evolt.org"
> > <thelist at lists.evolt.org>
> > Message: 17
> >
> > Hi,
> >
> > I want to include the minus symbol as a required character in a REGEX
> > expression, but am stumped as to how to do it..any suggestions?
> >
> > So far I have come up with: ereg("C-[A-Z]{4}|CF-[A-Z]{3}",$data) but it
> > doesn't work. I know I have to change the way I have displayed the minus
> > symbol, but I don't know what.
> >
> > I want to allow items like:
> > C-ABCD and CF-GHI
> >
> > Cheers
> > Alexis
> >
>
>



More information about the thelist mailing list