On Thu, Aug 2, 2018 at 8:18 AM Timo Paulssen <t...@wakelift.de> wrote:

> Is this what you want?
>
> perl6 -e 'say "12345" ~~ /^<+alnum -alpha>+$/'
> 「12345」
>
> perl6 -e 'say "123a45" ~~ /^<+alnum -alpha>+$/'
> Nil


On Sun, Aug 5, 2018 at 6:41 PM Arthur Ramos Jr. <lens...@winningweb.com>
wrote:

> my $x = "9.0v1"; die "Horribly" if $x =~ /[\p{L}]+/;
>
>
For that matter, you can also just use plain old unary +  (
https://docs.perl6.org/routine/+#(Operators)_prefix_+)

~$ perl6 -e 'say +"12345"'
12345
~$ perl6 -e 'say +"123a45"'
Cannot convert string to number: trailing characters after number in
'123⏏a45' (indicated by ⏏)
  in block <unit> at -e line 1

~$ perl6 -e 'say +"9.0v1"'
Cannot convert string to number: trailing characters after number in
'9.0⏏v1' (indicated by ⏏)
  in block <unit> at -e line 1

If the string is numeric, you get the number back, otherwise an exception.

Curt

Reply via email to