Page 1 of 1

whats the regex for this expression ??

Posted: Tue Apr 10, 2007 5:54 am
by PHPycho
what will be the regex for the string that contains only alphanumeric ,commma ,space .
Thanks in advance to all of you

Posted: Tue Apr 10, 2007 7:08 am
by Oren

Code: Select all

$regex = '/^[a-z0-9, ]+$/i';
Note: an empty string won't match this pattern. If you want to allow empty strings too: change the '+' into '*'.

Posted: Tue Apr 10, 2007 7:57 am
by feyd
Remember to trim() that sucker afterward. ;)

Posted: Tue Apr 10, 2007 11:37 am
by matthijs
Well indeed, that's a good idea :)

Posted: Tue Apr 10, 2007 11:32 pm
by PHPycho
whats the regex for newline.
thank you

Posted: Wed Apr 11, 2007 5:06 am
by Oren
PHPycho wrote:whats the regex for newline.
What do you mean by that?

Posted: Wed Apr 11, 2007 6:30 am
by aaronhall
PHPycho wrote:whats the regex for newline.
\n, just like always (it's got to be enclosed in double-quotes if you use the code above)

Posted: Wed Apr 11, 2007 7:33 am
by feyd
aaronhall wrote:\n, just like always (it's got to be enclosed in double-quotes if you use the code above)
No, it doesn't.

Code: Select all

[feyd@home]>php -r "$a = '#\n#'; echo preg_match($a,chr(0x0A));"
1

Posted: Wed Apr 11, 2007 7:38 am
by Oren
I'm still not sure what you mean, but try this:

Code: Select all

$regex = '/^[a-z0-9, \n\r]+$/i';
P.S Single quotes seem to work too. \n alone doesn't work for me while \n\r does.

Posted: Wed Apr 11, 2007 7:50 am
by John Cartwright
Oren wrote:I'm still not sure what you mean, but try this:

Code: Select all

$regex = '/^[a-z0-9, \n\r]+$/i';
P.S Single quotes seem to work too. \n alone doesn't work for me while \n\r does.
Which is why PHP_EOS should be used for cross-platform applications :wink:

Posted: Wed Apr 11, 2007 8:07 am
by aaronhall
feyd wrote:
aaronhall wrote:\n, just like always (it's got to be enclosed in double-quotes if you use the code above)
No, it doesn't.

Code: Select all

[feyd@home]>php -r "$a = '#\n#'; echo preg_match($a,chr(0x0A));"
1
Indeed, thanks

Posted: Wed Apr 11, 2007 8:48 am
by Oren
Jcart wrote:Which is why PHP_EOS should be used for cross-platform applications :wink:
You mean PHP_EOL :wink:

Posted: Fri Apr 20, 2007 1:35 am
by PHPycho
Knock Knock
Help again..
Whats the regex for the format like
883 02 12313545
or
883-02-12313545
thanks in advance for help

Posted: Fri Apr 20, 2007 3:01 am
by Chris Corbyn
aaronhall wrote:
PHPycho wrote:whats the regex for newline.
\n, just like always (it's got to be enclosed in double-quotes if you use the code above)
\n is actually part of the pattern so it doesn't. Hexadec such as \x0A work in single quotes in patterns too.

Posted: Fri Apr 20, 2007 6:07 am
by Kieran Huggins
we seem to be turning into a regex factory instead of a regex classroom...

play here: http://www.cuneytyilmaz.com/prog/jrx/

we're here if you get stuck