Re: RegEx - Chk for special chars
- From: shimmyshack <matt.farey@xxxxxxxxx>
- Date: 30 Apr 2007 05:52:05 -0700
On Apr 30, 9:08 am, gosha bine <stereof...@xxxxxxxxx> wrote:
On 30.04.2007 01:37 M Kinnear wrote:
I want to check a string only contains a-z 0-9 ( ) . and #
I've used
ereg("^[a-zA-z0-9().#]*)$"),$instr)
This line has a syntax error. I'd suggest
preg_match('/^[\w().#]*$/D', $instr)
which parses a string correctly until I try and parse a !,",£,$ ... or any
of the other special/reserved characters.
First q: what am I doing wrong
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
Inside a character class ([...]) only slash \ caret ^ and dash - have
special meaning and should be escaped. All other chars are taken
literally. When using double quotes, you also have to escape dollar sign
when it comes before a letter.
Thanks
Matt
--
gosha bine
extended php parser ~http://code.google.com/p/pihipi
blok ~http://www.tagarga.com/blok
and one more thing, the OP had
[a-zA-z]
I think he needs [a-zA-Z] as [A-z] allows more than upper and lower
case letters
.
- References:
- RegEx - Chk for special chars
- From: M Kinnear
- Re: RegEx - Chk for special chars
- From: gosha bine
- RegEx - Chk for special chars
- Prev by Date: Re: Tool to validate HTML code with PHP tags?
- Next by Date: Re: Manipulating binary data
- Previous by thread: Re: RegEx - Chk for special chars
- Next by thread: Re: RegEx - Chk for special chars
- Index(es):
Relevant Pages
|