Course of Raku / Regexes and grammars / Regexes / Matching strings / Exercises / The matched text

Solution: The matched text

Here is a possible solution to the task.

Code

'database' ~~ /base/;
say $/.Str;

🦋 You can find the source code in the file matched-text.raku.

Output

base

Comments

  1. Every smartmatch stores its result in the special match variable $/, so there is no need to assign it to a variable of our own.

  2. The match object holds the matched text; calling .Str on $/ returns that text as an ordinary string. Printing the match object directly would have shown 「base」 instead.

Course navigation

The matched text   |   Where is the digit