Course of Raku / Regexes and grammars / Regexes / Anchors / Exercises / The whole string

Solution: The whole string

Here is a possible solution to the task.

Code

say so 'hello' ~~ /^ <[a..z]>+ $/;

🦋 You can find the source code in the file whole-string.raku.

Output

True

Comments

  1. The ^ and $ anchors pin the pattern to the start and end of the string.

  2. Between them, <[a..z]>+ must account for every character, so a string with a capital letter or a space, such as Hello there, would fail.

Course navigation

The whole string   |   A whole word