[thelist] RE: REGEX problem

Mike Boucher mike at xlr8studios.com
Fri Feb 27 19:35:51 CST 2004


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