newbie help with ereg

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi all,

I apologize in advance for how basic this question is, but can someone
please tell me why in the world this statement

ereg( '[\w]', 'abcdef' );

always returns false? Thanks.

Re: newbie help with ereg wrote:

Quoted text here. Click to load it

Because 'abcdef' neither contains a 'w' or '' character

Try looking into the more powerful PCRE functions
I'll bet you'll find that \w works here

$ok = preg_match('#[\w]#', "abcdef") == 1;

$ok should be true now

Re: newbie help with ereg

The POSIX regexp functions don't support the PERL extensions. IIRC, the
equivalent to \w in POSIX syntax is [[:alnum:]].

Re: newbie help with ereg

ereg('[[:alnum:]], 'abcdef'); <- match alpha numeric characters


ereg('[a-z], 'abcdef'); <- only matching 'a to z' (lower case)

look this site for more information about regexp

Site Timeline