Course of Raku / Regexes and grammars / Regexes

Captures

Matching tells you whether a pattern is present. A capture goes further: it remembers a particular piece of the match so you can use it afterwards. This is how you pull a year out of a date, a name out of a record, or the parts of any structured string.

Raku has two kinds of captures: positional ones, numbered from zero, and named ones, which you label yourself. Both are reached through the match object.

Topics in this section

Practice

Complete the quizzes that cover the contents of this section.

Exercises

This section contains 4 exercises. Examine all the topics of this section before doing the coding practice.

  1. Split a filename
  2. City and country
  3. Last name first
  4. Initial and surname

Course navigation

Solution: Two to four   |   Positional captures