harangzsolt33 has asked for the wisdom of the Perl Monks concerning the following question:
I am so frustrated, I have been reading the RegExp help for awhile, and I just don't get it. All I want to do is find out if a string is made up of a set of characters, and print either 1 or 0 (true or false).
Here is the character set:
0-9 - all numbers a-zA-Z - all letters . - the decimal point \ - backslash / - forward slash - - the dash _ - the underline % - percent sign $ - dollar sign ' - single quote () - parenthesis {} - opening and closing brackets & - the and sign ! - the exclamation point ~ - wave ` - tick or whatever this is @ - the at sign # - the comment character ^ - this guy
Any other character is NOT allowed. SO, if the string contains a character that is not allowed, then I want the match to evaluate to 1, otherwise 0. This way I can tell whether the string has any illegal characters in it.
Here is the code I have written, which doesn't do anything. :-P :-(
my $STR1 = '///?///'; my $STR2 = 'ABC_ABC'; print "\n" . ($STR1 =~ /(\d\w.\/~-_!@#$%\^&{}\(\).'`)/); print "\n" . ($STR2 =~ /(\d\w.\/~-_!@#$%\^&{}\(\).'`)/);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How would you write this RegExp?
by BrowserUk (Patriarch) on Jul 26, 2016 at 21:26 UTC | |
by harangzsolt33 (Deacon) on Jul 26, 2016 at 21:49 UTC | |
|
Re: How would you write this RegExp?
by AnomalousMonk (Archbishop) on Jul 27, 2016 at 00:28 UTC | |
|
Re: How would you write this RegExp?
by Anonymous Monk on Jul 26, 2016 at 21:32 UTC | |
by harangzsolt33 (Deacon) on Jul 26, 2016 at 22:57 UTC | |
by MidLifeXis (Monsignor) on Jul 27, 2016 at 11:21 UTC | |
by Anonymous Monk on Jul 27, 2016 at 00:12 UTC | |
|
Re: How would you write this RegExp?
by ww (Archbishop) on Jul 27, 2016 at 12:42 UTC |