By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,871 Members | 1,617 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,871 IT Pros & Developers. It's quick & easy.

regular expression

P: 5

i should check if a username ($username) is like unix, so this username must start with a char, contains max 16 chars, all tiny and in general can contains just chars, numbers, and dot.

all this with the use of regular expression.

someone can help me?

Apr 6 '10 #1
Share this Question
Share on Google+
4 Replies

Expert Mod 2.5K+
P: 3,503
Sure, we can help you, but you are going to have to do the legwork so that you can learn. Try to write it and if you get stuck, post your code here so that we can see it and help you.


Apr 6 '10 #2

P: 5
i have a text file with a list of username, one for each row:


the username ok are number: 1,3,4

the second start with number so it's no good
the fifth start with dot so it's no good
the sisxt contains --- so it's no good,

now if I do from console:

grep '^[a-z][a-z0-9.]{3,16}$' example

where example is name of my file, appear nothing.

if i'll do:

grep '^[a-z][a-z0-9.]' example:


so so...because appear a substring match such as

So my problems are two:

1. min and max of string that doesn't work
2. problem with substring match.

Edit/Delete Message
Apr 6 '10 #3

P: 70
I answered this question on another forum:
Apr 6 '10 #4

Expert 100+
P: 785
"grep" can only use basic regular expression That means no quantifiers (that you call "min and max of string"). Use "egrep" for full regular expression (or "sed" or "perl").
Apr 9 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.