perlre question - negate POSIX charachter classes 
Author Message
 perlre question - negate POSIX charachter classes

Ok, I need some help understanding what this means.

from perlre :

qq(

You can negate the [::] character classes by prefixing the class name with a
'^'. This is a Perl extension. For example:

    POSIX       trad. Perl  utf8 Perl
    [:^digit:]      \D      \P{IsDigit}
    [:^space:]      \S      \P{IsSpace}
    [:^word:]       \W      \P{IsWord}

)

Huh??

Ok. Why negate the calsses. Why would you use [:^digit:]. You can use
[:digit:], \D, or \P{IsDigit} right? What does [:^digit:] do?

Thanks,

-- Matt



Wed, 23 Feb 2005 13:38:47 GMT  
 perlre question - negate POSIX charachter classes

Quote:

> from perlre :

> qq(

> You can negate the [::] character classes by prefixing the class
> name with a '^'. This is a Perl extension. For example:

>     POSIX       trad. Perl  utf8 Perl
>     [:^digit:]      \D      \P{IsDigit}
>     [:^space:]      \S      \P{IsSpace}
>     [:^word:]       \W      \P{IsWord}

> )

> Huh??

> Ok. Why negate the calsses. Why would you use [:^digit:]. You
> can use [:digit:], \D, or \P{IsDigit} right?

[:digit:] matches a digit and the others don't.

Quote:
> What does [:^digit:] do?

It matches a non-digit.

This is the same distinction as between \d and \D.

And if you don't know what *that* means:

  ~/perl >  perl -le 'print "1x" =~ /(\d)/'
  1
  ~/perl >  perl -le 'print "1x" =~ /(\D)/'
  x

--
Steve

perldoc -qa.j | perl -lpe '($_)=m("(.*)")'



Wed, 23 Feb 2005 14:26:32 GMT  
 perlre question - negate POSIX charachter classes


Quote:
> [:digit:] matches a digit and the others don't.

> > What does [:^digit:] do?

> It matches a non-digit.

> This is the same distinction as between \d and \D.

> And if you don't know what *that* means:

>   ~/perl >  perl -le 'print "1x" =~ /(\d)/'
>   1
>   ~/perl >  perl -le 'print "1x" =~ /(\D)/'
>   x

> --
> Steve

> perldoc -qa.j | perl -lpe '($_)=m("(.*)")'

After looking at it a few more times, I finally figured that out. Thanks --
Matt


Thu, 24 Feb 2005 13:15:36 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. POSIX Charcter Classes and tr

2. perlre question

3. Regex question (negating a charater sequence).

4. POSIX::strftime() error under RH7, perl 5.6.0, POSIX 1.03

5. POSIX::tmpnam but no POSIX::tempnam

6. Newbie: the backspace charachter "\b" [repost]

7. Newbie: the backspace charachter "\b"

8. NET::LDAP and special charachters

9. split after a number of charachters?

10. How to I replace charachter?

11. Escape Charachter in PERL5

12. What is the octal range for meta charachters?

 

 
Powered by phpBB® Forum Software