in reply to Regex - Char Class Question

I don't think it is so much the tilde(~)being at the end but the hyphen (-) not being on one of the ends. That is, if the hyphen is not at either end of the character class then it becomes a range for whatever two chars it is in between.This should work the same as all the others for instance:
$a =~ /^[-\w.~]+$/

-enlil

Replies are listed 'Best First'.
Re: Re: Regex - Char Class Question
by diotalevi (Canon) on Dec 10, 2003 at 18:35 UTC
    See perlop. If you're going to put a ] or - character into your character class then it has to be either escaped or be placed at the front after the optional ^,
      See perlop.

      Actually, see perlre.

      If you're going to put a ] or - character into your character class then it has to be either escaped or be placed at the front after the optional ^,

      Or placed at the end immediately before the closing square bracket.

      The relevant passage from perlre:

      If you want either "-" or "]" itself to be a member of a class, put it at the start of the list (possibly after a "^"), or escape it with a backslash. "-" is also taken literally when it is at the end of the list, just before the closing "]".

      -sauoq
      "My two cents aren't worth a dime.";
      

      I knew I could escape the '-', I just wanted figure out what I was missing, was driving me nuts.

      Thanks for the reply!

Re: Re: Regex - Char Class Question
by sth (Priest) on Dec 10, 2003 at 18:39 UTC

    ..Thanks Enlil! I knew it was something obvious, just needed someone to point it out to me. :-)