kiat has asked for the wisdom of the Perl Monks concerning the following question:
I'm wondering if it's possible to have a single regex that accepts a string if it's one of the following:
a) letters only
b) letters plus underscore
c) letters with numbers
d) letters plus underscore plus numbers
Strings that contain purely numbers or numbers with underscores are unacceptable.
Thanks in anticipation :)
Update: Thanks! Funny, I kept thinking it must be done with two regexes. Btw, from Re: A single regex, I'm wondering if it would still be doable with a single regex with one more constraint added:
Maximally one underscore.
Update: Wow, regex is really quite an art and a science in itself. Thanks to all for helping :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: A single regex
by ccn (Vicar) on Sep 10, 2004 at 14:29 UTC | |
|
Re: A single regex
by BrowserUk (Patriarch) on Sep 10, 2004 at 14:34 UTC | |
|
Re: A single regex
by Roy Johnson (Monsignor) on Sep 10, 2004 at 15:27 UTC | |
|
Re: A single regex
by Sidhekin (Priest) on Sep 10, 2004 at 15:49 UTC | |
|
Re: A single regex
by BrowserUk (Patriarch) on Sep 10, 2004 at 15:22 UTC | |
|
Re: A single regex
by graff (Chancellor) on Sep 10, 2004 at 17:14 UTC | |
|
Re: A single regex
by Anonymous Monk on Sep 10, 2004 at 14:42 UTC | |
|
Re: A single regex
by Crian (Curate) on Sep 10, 2004 at 14:31 UTC |