expression problem

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

expression problem

Post by itsmani1 »

Here is my expression:

Code: Select all

$regex="/^[a-zA-Z0-9_\.\-\;\:]{5,50}$/";
It don't allow space, it works fine with "AhmedCenter" but don't with "Dizyn inc"
Please help me i want it work with "Dizyn inc" means it can allow spaces as well.

thank you
User avatar
GeertDD
Forum Contributor
Posts: 274
Joined: Sun Oct 22, 2006 1:47 am
Location: Belgium

Post by GeertDD »

Well, add a space inside the character class...

Code: Select all

$regex="/^[a-zA-Z0-9_\.\-\;\: ]{5,50}$/";
And then clean it up:

Code: Select all

$regex = '/^[-a-z0-9_.;: ]{5,50}$/i';
regexpert
Forum Newbie
Posts: 7
Joined: Sat Oct 20, 2007 3:41 am

Space

Post by regexpert »

you can add \s into the expression for space.

Code: Select all

$regex = '/^[-a-z0-9_.;:\s]{5,50}$/i';
User avatar
GeertDD
Forum Contributor
Posts: 274
Joined: Sun Oct 22, 2006 1:47 am
Location: Belgium

Re: Space

Post by GeertDD »

regexpert wrote:you can add \s into the expression for space.

Code: Select all

$regex = '/^[-a-z0-9_.;:\s]{5,50}$/i';
A space is what you get when you hit the space bar of your keyboard. The \s metacharacter includes spaces but other whitespace as well, e.g. tabs and newlines. I doubt itsmani1 wants to allow those as well.
Post Reply