Course of Raku / Regexes and grammars / Regexes

Substitution and replacement

Matching finds and extracts text. Substitution goes one step further and changes it — replacing the matched part with something else. This is how you censor a word, reformat a date, or clean up a string.

This section covers the s/// operator, how to use captures in the replacement, and tr///, which replaces characters one for one.

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. Censor a word
  2. Reformat a date
  3. Lower-case letters
  4. Mask the digits

Course navigation

Solution: All the numbers   |   The substitution operator