954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

regular expression

so I am trying to write a regular expression lets just take this case for an example:

^[0-9a-z]{5,9}$


OR an empty string, how would I add that part?

I tried stuff like:

^([0-9a-z]{5,9}|[]{0})$


but to no avail, any ideas?

paradox814
Posting Whiz
351 posts since Oct 2004
Reputation Points: 13
Solved Threads: 4
 

My suggestion would be to avoid putting so much overhead in the regular expression engine for such a simple test. You can accomplish what you want in PHP by doing something like:
[PHP]
# Assuming you are testing $string...
if(preg_match('/^[0-9a-z]{5,9}$/',$string) || strlen($string) < 1) {
# Do things here.
}
[/PHP]
How about that?

fisheye
Newbie Poster
11 posts since Jan 2006
Reputation Points: 10
Solved Threads: 0
 

^[0-9a-z]{5,9}$|^$

Troy
Posting Whiz
362 posts since Jun 2005
Reputation Points: 36
Solved Threads: 6
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You