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.\/~-_!@#$%\^&{}\(\).'`)/);

In reply to How would you write this RegExp? by harangzsolt33

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.