ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I looked at those pages but, I don't understand Greek. So, let me re-ask...
Can anyone give me a regex that will match non-[A-Za-z0-9@.-_] characters in an IF statement?
If you want to play with regexes, you're going to need to learn a little Greek. You might have better luck if you start with perldoc perlrequick. In any case, here's a kind of ham-handed approach:
Code:
#!/usr/bin/env perl
use strict;
use warnings;
my $name;
do {
print "What's your choice of username:>> ";
chomp($name = <STDIN>);
if ($name =~ /[^-A-Za-z0-9@._]/) {
print "Tsk tsk: bad characters!\n";
}
} until ($name eq 'quit');
In a nutshell [] creates a character class. It says look for the stuff inside the square brackets. If you use [^], you are doing a negative character class. So it says, look for anything other than what's inside the square brackets. So, I took what you said were the allowed characters, and I said "If you find anything that isn't one of these, scold the user." The only real trick there is that if you want to search for a literal '-' in a character class you need to put it first or escape it (\-). Other than that, it's pretty much straightforward.
Last edited by Telemachos; 04-28-2009 at 06:25 PM.
Sergei, thank you for your replies but, I am not a programmer and I do not have that mindset. I try and do as little coding as possible.
'RTFM' replies do me no good. I need examples of how things work. I have read Perl docs until my eyes bleed and I do not understand them (same with man pages), they are useless to me. I need examples to understand.
Telemachos reply, "/[^-A-Za-z0-9@._]/" explains it all to me...
// = This is a regex
^ = not the following
-A-Za-z0-9@._ = allowed characters
[] = match the characters inside these.
I understand.
54 lines of Perldoc gibberish just confuses me. It is the same as Greek.
theNbomr I would like to build a house. I don't want to use a hammer or a saw, and I don't want to learn any builder's techniques.
--- rod.
No, more like: "You want to build a house? Here's a book (with no pictures), figure out how to do dovetail joints by reading 54 lines of text."
If I wanted elitism, I'd post on FreeBSD forums...
After having read quite a bit about construction methods, I do know that dovetail joints are rarely used in homebuilding. And the point is that if you want to do something that you don't already know, it serves you well to do a little studying. That's how those who you expect to hand you an answer learned it.
Allegedly, you want advice on programming, since 'This forum is for all programming questions' and you put a programming language in the subject line of your post. It isn't elitism, it is on-topic. Specific references to authorative documents seem like appropriate forms of help. The helpful people in this forum are generally loath to simply do your work for you, but are almost universally willing to help you learn for yourself.
theNbomr - I don't know of one single carpenter that ever learned how to build a house by reading a manual. They all learned by example (watching it being done and apprenticing).
I've already said that I am not a programmer, I do not have the mindset. I do what I must and I learn by example.
RTFM replies are useless and elitist. If I understood manuals, I would have said: "can someone point me to the instructions as to how to..." . I didn't, I said "can someone give me the small bit of code that I couldn't figure out on my own".
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.