Course of Raku / Regexes and grammars / Regexes / Quantifiers / Exercises

An optional sign

Problem

Write a pattern that matches an integer which may optionally start with a minus sign, followed by one or more digits. Test it on '-42' and print the match.

Example

The program prints:

「-42」

Solution

See the solution

Course navigation

Quiz — Quantifiers   |   Solution: An optional sign