in reply to negating POSIX regexp classes doesn't work as expected

  1. use POSIX;
  2. Double your brackets. The outer set tells perl it's a character class; the inner set is part of the POSIX coding for using named charsets.

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: negating POSIX regexp classes doesn't work as expected
by tlm (Prior) on Apr 11, 2005 at 23:20 UTC

    I don't think one needs use POSIX, at least with the more recent versions of perl; e.g. with v5.8.4:

    #!perl -l use strict; use warnings; my $s = 'a1b2c3'; print for $s =~ /[[:alpha:]]/g; print for $s =~ /[[:digit:]]/g; __END__ a b c 1 2 3

    the lowliest monk

      You are correct, sir. I had thought it was use POSIX that caused it to bark at me when I didn't have the doubled brackets (POSIX syntax [: :] belongs inside character classes in regex), but it seems that it will bark without it. In either case, it only barks for positive char classes like [:digit:], not for negated ones like [:^digit:].

      Caution: Contents may have been coded under pressure.