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

regular expression

P: 5
Hi,

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?

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


numberwhun
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.

Regards,

Jeff
Apr 6 '10 #2

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

jdluk87
1isnotgood
luca.lupo
luca.lupo87
.asd.luca12
asd.sd---er.re

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:

jdluk87
luca.lupo
luca.lupo87
asd.sd---er.re

so so...because appear a substring match such as asd.sd---er.re.

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

Expert
P: 70
I answered this question on another forum:

http://perlguru.com/gforum.cgi?post=...=5200072#45457
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.