Skip to Content
Perl 6 Deep Dive
book

Perl 6 Deep Dive

by Andrew Shitov
September 2017
Beginner
402 pages
9h 52m
English
Packt Publishing
Content preview from Perl 6 Deep Dive

Character classes

A character class is a mechanism to request a match with a given list of characters. For example, to match hexadecimal numbers, we need to match a character with decimal digits 0 to 9 and with six letters a to f (also including their capital variants A to F).

In Perl 6 regexes, this can be written as a character class <[0..9 a..f A..F]>. Let us apply this regex to the list of uppercase Latin letters:

for 'A'..'Z' {    .print if /<[0..9 a..f A..F]>/;}

This prints the string ABCDEF, containing the letters that match the given regex.

Character classes may also include backslashed sequences. In the phone number regex, we can use a character class that will match with either a digit, a space, or a hyphen:

/ \+? <[\d\s\-]>+ /;
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Perl Hacks

Perl Hacks

Chromatic, Damian Conway, Curtis Ovid Poe, Curtis (Ovid) Poe
Learning Perl 6

Learning Perl 6

brian d foy
Think Perl 6

Think Perl 6

Laurent Rosenfeld, Allen B. Downey
Pro Perl

Pro Perl

Peter Wainwright

Publisher Resources

ISBN: 9781787282049Supplemental Content