If you can make reasonable assumptions about the number, for example, it is limited by word boundaries, you can do something like this:
regex number { ยซ # left word boundary \S+ # actual "number" ยป # right word boundary <?{ defined +"$/" }> }
The last line in this regular expression builds Match ( "$/" ), and then tries to convert it to a number ( + ). If it works, it returns a specific value, otherwise Failure . This string-to-number conversion recognizes the same syntax as the Perl 6 grammar. The <?{ ... }> construct is an assertion, so it fails if the expression inside returns a false value.
source share