Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

7.3. Character Classes

A character class, a list of possible characters inside square brackets ([ ]), matches any single character from within the class. It matches one character, but that character may be any of the ones listed.

For example, the character class [abcwxyz] may match any one of those seven characters. For convenience, you may specify a range of characters with a hyphen (-), so that class may also be written as [a-cw-z]. That didn't save much typing, but it's more common to make a character class like [a-zA-Z] to match any one letter out of that set of 52.[‡] You may use the same character shortcuts as in any double-quoted string to define a character, so the class [\000-\177] matches any seven-bit ASCII character.[§] Of course, a character class will be just part of a full pattern and will never stand on its own in Perl. For example, you might see code that says something like this:

[‡] Notice that those 52 don't include letters such as Å, É, Î, Ø, and Ü. But when Unicode processing is available, that particular character range is noticed and enhanced to do the right thing automatically.

[§] At least, if you use ASCII and not EBCDIC.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint