For Programmers: Free Programming Magazines  


Home > Archive > PHP Programming > April 2007 > Re: RegEx - Chk for special chars









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: RegEx - Chk for special chars
Benjamin

2007-04-29, 9:58 pm

On Apr 29, 6:37 pm, "M Kinnear" <newsgro...@lonyx.net> wrote:
> I want to check a string only contains a-z 0-9 ( ) . and #
>
> I've used
>
> ereg("^[a-zA-z0-9().#]*)$"),$instr)
>
> which parses a string correctly until I try and parse a !,",=A3,$ ... or =

any
> of the other special/reserved characters.
>
> First q: what am I doing wrong

I think putting \ before each character should do the trick.
> Second q: is there clarification on whether characters need to be escaped
> when part of a regex statement? i.e., should it be [$] or [\$] - some
> websites/posts state they should be escaped, others say they shouldn't

Have you looked at the PHP manual? Try http://www.php.net/manual/en/referen=
ce.pcre.pattern.syntax.php
>
> Thanks
>
> Matt



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com