txt: ## regexes.md
  ## Chunk 1 of 5
  Regexes
  
  Pattern matching against strings
  
  A *regular expression* is a sequence of characters that defines a certain text pattern, typically one that one wishes to find in some large body of text.
  
  In theoretical computer science and formal language theory, regular expressions are used to describe so-called [*regular languages*](https://en.wikipedia.org/wiki/Regular_language). Since their inception in the 1950's, practical implementations of regular expressions, for instance in the text search and replace functions of text editors, have outgrown their strict scientific definition. In acknowledgement of this, and in an attempt to disambiguate, a regular expression in Raku is normally referred to as a [`Regex`](/type/Regex) (from: *reg*ular *ex*pression), a term that is also in common use in other programming languages.
  
  In Raku, regexes are written in a [*domain-specific language*](https://en.wikipedia.org/wiki/Domain-specific_language), i.e. a sublanguage or [*slang*](/language/slangs). This page describes this language, and explains how regexes can be used to search for text patterns in strings in a process called *pattern matching*.
  
  # [Lexical conventions](#Regexes "go to top of document")[§](#Lexical_conventions "direct link")
  
  Fundamentally, Raku regexes are very much like subroutines: both are code objects, and just as you can have anonymous subs and named subs, you can have anonymous and named regexes.
  
  A regex, whether anonymous or named, is represented by a [`Regex`](/type/Regex) object. Yet, the syntax for constructing anonymous and named [`Regex`](/type/Regex) objects differs. We will therefore discuss them in turn.
  
  ## [Anonymous regex definition syntax](#Regexes "go to top of document")[§](#Anonymous_regex_definition_syntax "direct link")
  
  An anonymous regex may be constructed in one of the following ways:
  
  ```raku
  rx/pattern/;          # an anonymous Regex object; 'rx' stands for 'regex'
  /pattern/;            # an anonymous Regex object; shorthand for 'rx/.../'
  
  regex { pattern };    # keyword-declared anonymous regex; this form is
                        # intended for defining named regexes and is discussed
                        # in that context in the next section
  ```
  
  The `rx/ /` form has two advantages over the bare shorthand form `/ /`.
  
  Firstly, it enables the use of delimiters other than the slash, which may be used to improve the readability of the regex definition:
  
  ```raku
  rx{ '/tmp/'.* };      # the use of curly braces as delimiters makes this first
  rx/ '/tmp/'.* /;      # definition somewhat easier on the eyes than the second
  ```
  
  Although the choice is vast, not every character may be chosen as an alternative regex delimiter:
  
  * You cannot use whitespace or alphanumeric characters as delimiters. Whitespace in regex definition syntax is generally optional, except where it is required to distinguish from function call syntax (discussed hereafter).
  * Parentheses can be used as alternative regex delimiters, but only with a space between `rx` and the opening delimiter. This is because identifiers that are immediately followed by parentheses are always parsed as a subroutine call. For example, in `rx()` the [call operator](/language/operators#postcircumfix_(_)) `()` invokes the subroutine `rx`. The form `rx ( abc )`, however, *does* define a [`Regex`](/type/Regex) object.
  * Use of a colon as a delimiter would clash with the use of [adverbs](/language/regexes#Adverbs), which take the form `:adverb`; accordingly, such use of the colon is forbidden.
  * The hash character `#` is not available as a delimiter since it is parsed as the start of a [comment](/language/syntax#Single-line_comments) that runs until the end of the line.
  
  Secondly, the `rx` form allows you to insert [regex adverbs](/language/regexes#Regex_adverbs) between `rx` and the opening delimiter to modify the definition of the entire regex. This is equivalent to inserting the adverb at the beginning of the regex, but may be clearer:
  
  ```raku
  rx:r:s/pattern/;            # :r (:ratchet) and :s (:sigspace) adverbs, defining
                              # a ratcheting regex in which whitespace is significant
  rx/:r:s pattern/;           # Same, but possibly less readable
  ```
  
  Although anonymous regexes are not, as such, *named*, they may effectively be given a name by putting them inside a named variable, after which they can be referenced, both outside of an embedding regex and from within an embedding regex by means of [interpolation](/language/regexes#Regex_interpolation):
  
  ```raku
  my $regex = / R \w+ /;
  say "Zen Buddhists like Raku too" ~~ $regex; # OUTPUT: «｢Raku｣␤»
  
  my $regex = /pottery/;
  "Japanese pottery rocks!" ~~ / <$regex> /;  # Interpolation of $regex into /.../
  say $/;                                     # OUTPUT: «｢pottery｣␤»
  ```
  
  ## [Named regex definition syntax](#Regexes "go to top of document")[§](#Named_regex_definition_syntax "direct link")
  
  A named regex may be constructed using the `regex` declarator as follows:
  
  ```raku
  regex R { pattern };        # a named Regex object, named 'R'
  ```
  
  Unlike with the `rx` form, you cannot chose your preferred delimiter: curly braces are mandatory. In this regard it should be noted that the definition of a named regex using the `regex` form is syntactically similar to the definition of a subroutine:
  
  ```raku
  my sub   S { /pattern/ };   # definition of Sub object (returning a Regex)
  my regex R {  pattern  };   # definition of Regex object
  ```
  
  which emphasizes the fact that a [`Regex`](/type/Regex) object represents code rather than data:
  
  ```raku
  &S ~~ Code;                 # OUTPUT: «True␤»
  
  &R ~~ Code;                 # OUTPUT: «True␤»
  &R ~~ Method;               # OUTPUT: «True␤»   (A Regex is really a Method!)
  
  ```
  
  Also unlike with the `rx` form for defining an anonymous regex, the definition of a named regex using the `regex` keyword does not allow for adverbs to be inserted before the opening delimiter. Instead, adverbs that are to modify the entire regex pattern may be included first thing within the curly braces:
  
  ```raku
  regex R { :i pattern };     # :i (:ignorecase), renders pattern case insensitive
  ```
  
  Alternatively, by way of shorthand, it is also possible (and recommended) to use the `rule` and `token` variants of the `regex` declarator for defining a [`Regex`](/type/Regex) when the `:ratchet` and `:sigspace` adverbs are of interest:
  
  ```raku
  regex R { :r pattern };     # apply :r (:ratchet) to entire pattern
  
  ```
  
  and, alternatively
  
  ```raku
  token R { pattern };        # same thing: 'token' implies ':r'
  
  ```
  
  Or
  
  ```raku
  regex R { :r :s pattern };  # apply :r (:ratchet) and :s (:sigspace) to pattern
  
  ```
  
  with this alternative:
  
  ```raku
  rule  R { pattern };        # same thing: 'rule' implies ':r:s'
  
  ```
  
  Named regexes may be used as building blocks for other regexes, as they are methods that may called from within other regexes using the `<regex-name>` syntax. When they are used this way, they are often referred to as *subrules*; see for more details on their use [here](/language/regexes#Subrules). [`Grammar`](/type/Grammar)s are the natural habitat of subrules, but many common predefined character classes are also implemented as named regexes.
  
  ## [Regex readability: whitespace and comments](#Regexes "go to top of document")[§](#Regex_readability:_whitespace_and_comments "direct link")
  
  Whitespace in regexes is ignored unless the [`:sigspace`](/language/regexes#Sigspace) adverb is used to make whitespace syntactically significant.
  
  In addition to whitespace, comments may be used inside of regexes to improve their comprehensibility just as in code in general. This is true for both [single line comments](/language/syntax#Single-line_comments) and [multi line/embedded comments](/language/syntax#Multi-line_/_embedded_comments):
  
  ```raku
  my $regex =  rx/ \d ** 4            #`(match the year YYYY)
                   '-'
                   \d ** 2            # ...the month MM
                   '-'
                   \d ** 2 /;         # ...and the day DD
  
  say '2015-12-25'.match($regex);     # OUTPUT: «｢2015-12-25｣␤»
  ```
  
  ## [Match syntax](#Regexes "go to top of document")[§](#Match_syntax "direct link")
  
  There are a variety of ways to match a string against a regex. Irrespective of the syntax chosen, a successful match results in a [`Match`](/type/Match) object. In case the match is unsuccessful, the result is [`Nil`](/type/Nil). In either case, the result of the match operation is available via the special match variable [`$/`](/syntax/$$SOLIDUS).
  
  The most common ways to match a string against an anonymous regex `/pattern/` or against a named regex `R` include the following:
  
  * *Smartmatch: "string" ~~ /pattern/, or "string" ~~ /<R>/*
  
    [Smartmatching](/language/operators#index-entry-smartmatch_operator) a string against a [`Regex`](/type/Regex) performs a regex match of the string against the [`Regex`](/type/Regex):
  
    Raku highlighting
  
    ```
    say "Go ahead, make my day." ~~ / \w+ /;   # OUTPUT: «｢Go｣␤»
  
    my regex R { me|you };
    say "You talkin' to me?" ~~ / <R> /;       # OUTPUT: «｢me｣␤ R => ｢me｣␤»
    say "May the force be with you." ~~ &R ;   # OUTPUT: «｢you｣␤»
    ```
  
    The different outputs of the last two statements show that these two ways of smartmatching against a named regex are not identical. The difference arises because the method call `<R>` from within the anonymous regex `/ /` installs a so-called ['named capture'](/language/regexes#Named_captures) in the [`Match`](/type/Match) object, while the smartmatch against the named [`Regex`](/type/Regex) as such does not.
  * *Explicit topic match: m/pattern/, or m/<R>/*
  
    The match operator `m/ /` immediately matches the topic variable [`$_`](/language/variables#index-entry-topic_variable) against the regex following the `m`.
  
    As with the `rx/ /` syntax for regex definitions, the match operator may be used with adverbs in between `m` and the opening regex delimiter, and with delimiters other than the slash. However, while the `rx/ /` syntax may only be used with [*regex adverbs*](/language/regexes#Regex_adverbs) that affect the compilation of the regex, the `m/ /` syntax may additionally be used with [*matching adverbs*](/language/regexes#Matching_adverbs) that determine how the regex engine is to perform pattern matching.
  
    Here's an example that illustrates the primary difference between the `m/ /` and `/ /` syntax:
  
    Raku highlighting
  
    ```
    my $match;
    $_ = "abc";
    $match = m/.+/; say $match; say $match.^name; # OUTPUT: «｢abc｣␤Match␤»
    $match =  /.+/; say $match; say $match.^name; # OUTPUT: «/.+/␤Regex␤»
    ```
  * *Implicit topic match in sink and Boolean contexts*
  
    In case a [`Regex`](/type/Regex) object is used in sink context, or in a context in which it is coerced to [`Bool`](/type/Bool), the topic variable [`$_`](/language/variables#index-entry-topic_variable) is automatically matched against it:
  
    Raku highlighting
  
    ```
    $_ = "dummy string";        # Set the topic explicitly
  
    rx/ s.* /;                  # Regex object in sink context matches automatically
    say $/;                     # OUTPUT: «｢string｣␤»
  
    say $/ if rx/ d.* /;        # Regex object in Boolean context matches automatically
                                # OUTPUT: «｢dummy string｣␤»
    ```
  * *Match method: "string".match: /pattern/, or "string".match: /<R>/*
  
    The [`match`](/type/Str#method_match) method is analogous to the `m/ /` operator discussed above. Invoking it on a string, with a [`Regex`](/type/Regex) as an argument, matches the string against the [`Regex`](/type/Regex).
  * *Parsing grammars: grammar-name.parse($string)*
  
    Although parsing a [grammar](/language/grammars) involves more than just matching a string against a regex, this powerful regex-based text destructuring tool can't be left out from this overview of common pattern matching methods.
  
    If you feel that your needs exceed what simple regexes have to offer, check out this [grammar tutorial](/language/grammar_tutorial) to take regexes to the next level.
  
  # [Literals and metacharacters](#Regexes "go to top of document")[§](#Literals_and_metacharacters "direct link")
  
  A regex describes a pattern to be matched in terms of literals and metacharacters. Alphanumeric characters and the underscore `_` constitute the literals: these characters match themselves and nothing else. Other characters act as metacharacters and may, as such, have a special meaning, either by themselves (such as the dot `.`, which serves as a wildcard) or together with other characters in larger metasyntactic constructs (such as `<?before ...>`, which defines a lookahead assertion).
  
  In its simplest form a regex comprises only literals:
  
  ```raku
  /Cześć/;           # "Hello" in Polish
  /こんばんは/;        # "Good afternoon" in Japanese
  /Καλησπέρα/;       # "Good evening" in Greek
  ```
  
  If you want a regex to literally match one or more characters that normally act as metacharacters, those characters must either be escaped using a backslash, or be quoted using single or double quotes.
  
  The backslash serves as a switch. It switches a single metacharacter into a literal, and vice versa:
  
  ```raku
  / \# /;             # matches the hash metacharacter literally
  / \w /;             # turns literal 'w' into a character class (see below)
  /Hallelujah\!/;     # matches string 'Hallelujah!' incl. exclamation mark
  ```
  
  Even if a metacharacter does not (yet) have a special meaning in Raku, escaping (or quoting) it is required to ensure that the regex compiles and matches the character literally. This allows the clear distinction between literals and metacharacters to be maintained. So, for instance, to match a comma this will work:
  
  ```raku
  / \, /;             # matches a literal comma ','
  ```
  
  while this will fail:
  
  ```raku
  / ,  /;             # !! error: an as-yet meaningless/unrecognized metacharacter
                      # does not automatically match literally
  
  ```
  
  While an escaping backslash exerts its effect on the next individual character, both a single metacharacter and a sequence of metacharacters may be turned into literally matching strings by quoting them in single or double quotes:
  
  ```raku
  / "abc" /;          # quoting literals does not make them more literal
  / "Hallelujah!" /;  # yet, this form is generally preferred over /Hallelujah\!/
  
  / "two words" /;    # quoting a space renders it significant, so this matches
                      # the string 'two words' including the intermediate space
  
  / '#!:@' /;         # this regex matches the string of metacharacters '#!:@'
  ```
  
  Quoting does not necessarily turn every metacharacter into a literal, however. This is because quotes follow Raku's normal [rules for interpolation](/language/quoting#The_Q_lang). In particular, `｢…｣` quotes do not allow any interpolation; single quotes (either `'…'` or `‘…’`) allow the backslash to escape single quotes and the backslash itself; and double quotes (either `"…"` or `“…”`) enable the interpolation of variables and code blocks of the form `{…}`. Hence all of this works:
  
  ```raku
  / '\\\'' /;          # matches a backslash followed by a single quote: \'
  / ｢\'｣ /;       # also matches a backslash followed by a single quote
  my $x = 'Hi';
  / "$x there!" /;     # matches the string 'Hi there!'
  
  / "1 + 1 = {1+1}" /; # matches the string '1 + 1 = 2'
  ```
  
  while these examples illustrate mistakes that you will want to avoid:
  
  ```raku
  / '\' /;             # !! error: this is NOT the way to literally match a
                       # backslash because now it escapes the second quote
  
  /"Price tag $0.50"/; # !! error: "$0" is interpreted as the first positional
                       # capture (which is Nil), not as '$0'
  
  ```
  
  Strings are searched left to right, so it is enough if only part of the string matches the regex:
  
  ```raku
  if 'Life, the Universe and Everything' ~~ / and / {
      say ~$/;            # OUTPUT: «and␤»
      say $/.prematch;    # OUTPUT: «Life, the Universe ␤»
      say $/.postmatch;   # OUTPUT: « Everything␤»
      say $/.from;        # OUTPUT: «19␤»
      say $/.to;          # OUTPUT: «22␤»
  };
  ```
  
  Match results are always stored in the `$/` variable and are also returned from the match. They are both of type [`Match`](/type/Match) if the match was successful; otherwise both are of type [`Nil`](/type/Nil).
  
  # [Wildcards](#Regexes "go to top of document")[§](#Wildcards "direct link")
  
  An unescaped dot `.` in a regex matches any single character.
  
  So, these all match:
  
  ```raku
  'raku' ~~ /rak./;       # matches the whole string
  'raku' ~~ / rak . /;    # the same; whitespace is ignored
  'raku' ~~ / ra.u /;     # the . matches the k
  'raker' ~~ / rak. /;    # the . matches the e
  ```
  
  while this doesn't match:
  
  ```raku
  'raku' ~~ / . rak /;
  ```
  
  because there's no character to match before `rak` in the target string.
  
  Notably `.` also matches a logical newline `\n`:
  
  ```raku
  my $text = qq:to/END/
    Although I am a
    multi-line text,
    I can be matched
    with /.*/.
    END
    ;
  
  say $text ~~ / .* /;
  # OUTPUT: «｢Although I am a␤multi-line text,␤I can be matched␤with /.*/.␤｣»
  ```
  
  # [Character classes](#Regexes "go to top of document")[§](#Character_classes "direct link")
  
  ## [Backslashed character classes](#Regexes "go to top of document")[§](#Backslashed_character_classes "direct link")
  
  There are predefined character classes of the form `\w`. Its negation is written with an uppercase letter, `\W`.
  
  ### [`\n` and `\N`](#Regexes "go to top of document")[§](#\n_and_\N "direct link")
  
  `\n` matches a logical newline. `\N` matches a single character that's not a logical newline.
  
  The definition of what constitutes a logical newline follows the [Unicode definition of a line boundary](https://unicode.org/reports/tr18/#Line_Boundaries) and includes in particular all of: a line feed (LF) `\U+000A`, a vertical tab (VT) `\U+000B`, a form feed (FF) `\U+000C`, a carriage return (CR) `\U+000D`, and the Microsoft Windows style newline sequence CRLF.
  
  The interpretation of `\n` in regexes is independent of the value of the variable `$?NL` controlled by the [newline pragma](/language/pragmas#newline).
  
  ### [`\t` and `\T`](#Regexes "go to top of document")[§](#\t_and_\T "direct link")
  
  `\t` matches a single tab/tabulation character, `U+0009`. `\T` matches a single character that is not a tab.
  
  Note that exotic tabs like the `U+000B VERTICAL TABULATION` character are not included here.
  
  ### [`\h` and `\H`](#Regexes "go to top of document")[§](#\h_and_\H "direct link")
  
  `\h` matches a single horizontal whitespace character. `\H` matches a single character that is not a horizontal whitespace character.
  
  Examples of horizontal whitespace characters are
  
  ｢text｣ without highlighting
  
  ```
  
  
  ```
  
  U+0020 SPACE
  U+00A0 NO-BREAK SPACE
  U+0009 CHARACTER TABULATION
  U+2001 EM QUAD
  
  
  ```
  
  
  ```
  
  Vertical whitespace such as newline characters are explicitly excluded; those can be matched with `\v`; `\s` matches any kind of whitespace.
  
  ### [`\v` and `\V`](#Regexes "go to top of document")[§](#\v_and_\V "direct link")
  
  `\v` matches a single vertical whitespace character. `\V` matches a single character that is not vertical whitespace.
  
  Examples of vertical whitespace characters:
  
  ｢text｣ without highlighting
  
  ```
  
  
  ```
  
  U+000A LINE FEED
  U+000B VERTICAL TABULATION
  U+000C FORM FEED
  U+000D CARRIAGE RETURN
  U+0085 NEXT LINE
  U+2028 LINE SEPARATOR
  U+2029 PARAGRAPH SEPARATOR
  
  
  ```
  
  
  ```
  
  Use `\s` to match any kind of whitespace, not just vertical whitespace.
  
  ### [`\s` and `\S`](#Regexes "go to top of document")[§](#\s_and_\S "direct link")
  
  `\s` matches a single whitespace character. `\S` matches a single character that is not whitespace.
  
  ```raku
  say $/.prematch if 'Match the first word.' ~~ / \s+ /;
  # OUTPUT: «Match␤»
  ```
  
  ### [`\d` and `\D`](#Regexes "go to top of document")[§](#\d_and_\D "direct link")
  
  `\d` matches a single decimal digit (Unicode General Category *Number, Decimal Digit*, `Nd`); conversely, `\D` matches a single character that is *not* a decimal digit.
  
  ```raku
  'ab42' ~~ /\d/ and say ~$/;     # OUTPUT: «4␤»
  'ab42' ~~ /\D/ and say ~$/;     # OUTPUT: «a␤»
  ```
  
  Note that not only the Arabic digits (commonly used in the Latin alphabet) match `\d`, but also decimal digits from other scripts.
  
  Examples of decimal digits include:
  
  ｢text｣ without highlighting
  
  ```
  
  
  ```
  
  U+0035 5 DIGIT FIVE
  U+0BEB ௫ TAMIL DIGIT FIVE
  U+0E53 ๓ THAI DIGIT THREE
  U+17E5 ៥ KHMER DIGIT FIVE
  
  
  ```
  
  
  ```
  
  Also note that "decimal digit" is a narrower category than "Number" because (Unicode) numbers include not only decimal numbers (`Nd`) but also letter numbers (`Nl`) and other numbers (`No`) Examples of Unicode numbers that are not decimal digits include:
  
  ｢text｣ without highlighting
  
  ```
  
  
  ```
  
  U+2464 ⑤ CIRCLED DIGIT FIVE
  U+2476 ⑶ PARENTHESIZED DIGIT THREE
  U+2083 ₃ SUBSCRIPT THREE
  
  
  ```
  
  
  ```
  
  To match against all numbers, you can use the [Unicode property](#Unicode_properties) `N`:
  
  ```raku
  say '⑤' ~~ /<:N>/ # OUTPUT: «｢⑤｣␤»
  ```
  
  ### [`\w` and `\W`](#Regexes "go to top of document")[§](#\w_and_\W "direct link")
  
  `\w` matches a single word character, i.e. a letter (Unicode category L), a digit or an underscore. `\W` matches a single character that is not a word character.
  
  Examples of word characters:
  
  ｢text｣ without highlighting
  
  ```
  
  
  ```
  
  0041 A LATIN CAPITAL LETTER A
  0031 1 DIGIT ONE
  03B4 δ GREEK SMALL LETTER DELTA
  03F3 ϳ GREEK LETTER YOT
  0409 Љ CYRILLIC CAPITAL LETTER LJE
  
  
  ```
  
  
  ```
  
  ### [`\c` and `\C`](#Regexes "go to top of document")[§](#\c_and_\C "direct link")
  
  `\c` takes a parameter delimited by square-brackets which is the name of a Unicode character as it appears in the [Unicode Character Database (UCD)](https://unicode.org/ucd/) and matches that specific character. For example:
  
  ```raku
  'a.b' ~~ /\c[FULL STOP]/ and say ~$/;    # OUTPUT: «.␤»
  ```
  
  `\C` matches a single character that is not the named Unicode character.
  
  Note that the word "character" is used, here, in the sense that the UCD does, but because Raku uses [NFG](/language/glossary#NFG), combining code points and the base characters to which they are attached, will generally not match individually. For example if you compose `"ü"` as `"u\x[0308]"`, that works just fine, but matching may surprise you:
  
  ```raku
  say "u\x[0308]" ~~ /\c[LATIN SMALL LETTER U]/;    # OUTPUT: «Nil␤»
  ```
  
  To match the unmodified character, you can use the [`:ignoremark`](#Ignoremark) adverb.
  
  ### [`\x` and `\X`](#Regexes "go to top of document")[§](#\x_and_\X "direct link")
  
  `\x` takes a parameter delimited by square-brackets which is the hexadecimal representation of the Unicode codepoint representing the character to be matched. For example:
  
  ```raku
  'a.b' ~~ /\x[2E]/ and say ~$/;    # OUTPUT: «.␤»
  ```
  
  `\X` matches a single character that is not the given Unicode codepoint.
  
  In addition, `\x` and `\X` can be used without square brackets, in which case, any characters that follow the `x` or `X` that are valid hexadecimal digits will be consumed. This means that all of these are equivalent:
  
  ```raku
  /\x2e/ and /\x002e/ and /\x00002e/
  ```
  
  But this format can be ambiguous, so the use of surrounding whitespace is highly recommended in non-trivial expressions.
  
  For additional provisos with respect to combining codepoints, see [`\c` and `\C`](#\c_and_\C).
  
  ## [Predefined character classes](#Regexes "go to top of document")[§](#Predefined_character_classes "direct link")
  
  | Class | Shorthand | Description |
  | --- | --- | --- |
  | <alpha> |  | Alphabetic characters plus underscore (\_) |
  | <digit> | \d | Decimal digits |
  | <xdigit> |  | Hexadecimal digit [0-9A-Fa-f] |
  | <alnum> | \w | <alpha> plus <digit> |
  | <punct> |  | Punctuation and Symbols (only Punct beyond ASCII) |
  | <graph> |  | <alnum> plus <punct> |
  | <space> | \s | Whitespace |
  | <cntrl> |  | Control characters |
  | <print> |  | <graph> plus <space>, but no <cntrl> |
  | <blank> | \h | Horizontal whitespace |
  | <lower> | <:Ll> | Lowercase characters |
  | <upper> | <:Lu> | Uppercase characters |
  
  The predefined character classes in the leftmost column are all of the form `<name>`, a hint to the fact that they are implemented as built-in [named regexes](/language/regexes#Subrules). As such they are subject to the usual capturing semantics. This means that if a character class is called with the syntax `<name>` (i.e. as indicated in the leftmost column), it will not only match, but also capture, installing a correspondingly named ['named capture'](/language/regexes#Named_captures) in the resulting [`Match`](/type/Match). In case just a match and no capture is desired, the capture may be suppressed through the use of call syntax that includes a leading dot: `<.name>`.
  
  ## [Predefined Regexes](#Regexes "go to top of document")[§](#Predefined_Regexes "direct link")
  
  Besides the built-in character classes, Raku provides built-in [anchors](/language/regexes#Anchors) and [zero-width assertions](/language/regexes#Zero-width_assertions) defined as named regexes. These include `wb` (word boundary), `ww` (within word), and `same` (the next and previous character are the same). See the [anchors](/language/regexes#Anchors) and [zero-width assertions](/language/regexes#Zero-width_assertions) sections for details.
  
  Raku also provides the two predefined tokens (i.e., regexes that don't [backtrack](/language/regexes#Backtracking)) shown below:
  
  | Token | Regex equivalent | Description |
  | --- | --- | --- |
  | <ws> | <!ww> \s\*: | Word-separating whitespace (including zero, e.g. at EOF) |
  | <ident> | <.alpha> \w\*: | Basic identifier (no support for ' or -). |
  
  ## [Unicode properties](#Regexes "go to top of document")[§](#Unicode_properties "direct link")
  
  The character classes mentioned so far are mostly for convenience; another approach is to use Unicode character properties. These come in the form `<:property>`, where `property` can be a short or long Unicode General Category name. These use pair syntax.
  
  To match against a Unicode property you can use either smartmatch or [`uniprop`](/routine/uniprop):
  
  ```raku
  "a".uniprop('Script');                 # OUTPUT: «Latin␤»
  "a" ~~ / <:Script<Latin>> /;           # OUTPUT: «｢a｣␤»
  "a".uniprop('Block');                  # OUTPUT: «Basic Latin␤»
  "a" ~~ / <:Block('Basic Latin')> /;    # OUTPUT: «｢a｣␤»
  ```
  
  These are the Unicode general categories used for matching:
  
  | Short | Long |
  | --- | --- |
  | L | Letter |
  | LC | Cased\_Letter |
  | Lu | Uppercase\_Letter |
  | Ll | Lowercase\_Letter |
  | Lt | Titlecase\_Letter |
  | Lm | Modifier\_Letter |
  | Lo | Other\_Letter |
  | M | Mark |
  | Mn | Nonspacing\_Mark |
  | Mc | Spacing\_Mark |
  | Me | Enclosing\_Mark |
  | N | Number |
  | Nd | Decimal\_Number or digit |
  | Nl | Letter\_Number |
  | No | Other\_Number |
  | P | Punctuation or punct |
  | Pc | Connector\_Punctuation |
  | Pd | Dash\_Punctuation |
  | Ps | Open\_Punctuation |
  | Pe | Close\_Punctuation |
  | Pi | Initial\_Punctuation |
  | Pf | Final\_Punctuation |
  | Po | Other\_Punctuation |
  | S | Symbol |
  | Sm | Math\_Symbol |
  | Sc | Currency\_Symbol |
  | Sk | Modifier\_Symbol |
  | So | Other\_Symbol |
  | Z | Separator |
  | Zs | Space\_Separator |
  | Zl | Line\_Separator |
  | Zp | Paragraph\_Separator |
  | C | Other |
  | Cc | Control or cntrl |
  | Cf | Format |
  | Cs | Surrogate |
  | Co | Private\_Use |
  | Cn | Unassigned |
  
  For example, `<:Lu>` matches a single, uppercase letter.
  
  Its negation is this: `<:!property>`. So, `<:!Lu>` matches a single character that is not an uppercase letter.
  
  Categories can be used together, with an infix operator:
  
  | Operator | Meaning |
  | --- | --- |
  | + | set union |
  | \- | set difference |
  
  To match either a lowercase letter or a number, write `<:Ll+:N>` or `<:Ll+:Number>` or `<+ :Lowercase_Letter + :Number>`.
  
  It's also possible to group categories and sets of categories with parentheses; for example:
  
  ```raku
  say $0 if 'raku9' ~~ /\w+(<:Ll+:N>)/ # OUTPUT: «｢9｣␤»
  ```
  
  ## [Enumerated character classes and ranges](#Regexes "go to top of document")[§](#Enumerated_character_classes_and_ranges "direct link")
  
  Sometimes the pre-existing wildcards and character classes are not enough. Fortunately, defining your own is fairly simple. Within `<[ ]>`, you can put any number of single characters and ranges of characters (expressed with two dots between the end points), with or without whitespace.
  
  ```raku
  "abacabadabacaba" ~~ / <[ a .. c 1 2 3 ]>* /;
  # Unicode hex codepoint range
  "ÀÁÂÃÄÅÆ" ~~ / <[ \x[00C0] .. \x[00C6] ]>* /;
  # Unicode named codepoint range
  "αβγ" ~~ /<[\c[GREEK SMALL LETTER ALPHA]..\c[GREEK SMALL LETTER GAMMA]]>*/;
  # Non-alphanumeric
  '$@%!' ~~ /<[ ! @ $ % ]>+/  # OUTPUT: «｢$@%!｣␤»
  ```
  
  As the last line above illustrates, within `<[ ]>` you do *not* need to quote or escape most non-alphanumeric characters the way you do in regex text outside of `<[ ]>`. You do, however, need to escape the much smaller set of characters that have special meaning within `<[ ]>`, such as `\`, `[`, and `]`.
  
  To escape characters that would have some meaning inside the `<[ ]>`, precede the character with a `\`.
  
  ```raku
  say "[ hey ]" ~~ /<-[ \] \[ \s ]>+/; # OUTPUT: «｢hey｣␤»
  ```
  
  You do not have the option of quoting special characters inside a `<[ ]>` – a `'` just matches a literal `'`.
  
  Within the `< >` you can use `+` and `-` to add or remove multiple range definitions and even mix in some of the Unicode categories above. You can also write the backslashed forms for character classes between the `[ ]`.
  
  ```raku
  / <[\d] - [13579]> /;
  # starts with \d and removes odd ASCII digits, but not quite the same as
  / <[02468]> /;
  # because the first one also contains "weird" unicodey digits
  ```
  
  You can include Unicode properties in the list as well:
  
  ```raku
  /<:Zs + [\x9] - [\xA0] - [\x202F] >/
  # Any character with "Zs" property, or a tab, but not a "no-break space" or "narrow no-break space"
  ```
  
  To negate a character class, put a `-` after the opening angle bracket:
  
  ```raku
  say 'no quotes' ~~ /  <-[ " ]> + /;  # <-["]> matches any character except "
  ```
  
  A common pattern for parsing quote-delimited strings involves negated character classes:
  
  ```raku
  say '"in quotes"' ~~ / '"' <-[ " ]> * '"'/;
  ```
  
  This regex first matches a quote, then any characters that aren't quotes, and then a quote again. The meaning of `*` and `+` in the examples above are explained in the next section on quantifiers.
  
  Just as you can use the `-` for both set difference and negation of a single value, you can also explicitly put a `+` in front:
  
  ```raku
  / <+[123]> /  # same as <[123]>
  ```
  
  # [Quantifiers](#Regexes "go to