| 1 | package Regexp::Pattern::Int; | ||
| 2 | |||
| 3 | 1 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |
| 4 | 1 | our $DATE = '2020-05-27'; # DATE | |
| 5 | 1 | our $DIST = 'Regexp-Pattern-Int'; # DIST | |
| 6 | 1 | our $VERSION = '0.001'; # VERSION | |
| 7 | |||
| 8 | 1 | ▶ | use 5.010001; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | #use utf8; | ||
| 12 | |||
| 13 | 1 | our %RE; | |
| 14 | |||
| 15 | $RE{int} = { | ||
| 16 | 1 | summary => 'Integer number', | |
| 17 | pat => qr/[+-]?[0-9]+/, | ||
| 18 | examples => [ | ||
| 19 | {str=>'', anchor=>1, matches=>0}, | ||
| 20 | {str=>'123', anchor=>1, matches=>1}, | ||
| 21 | {str=>'+123', anchor=>1, matches=>1}, | ||
| 22 | {str=>'-123', anchor=>1, matches=>1}, | ||
| 23 | {str=>'123.1', anchor=>1, matches=>0}, | ||
| 24 | {str=>'1e2', anchor=>1, matches=>0}, | ||
| 25 | ], | ||
| 26 | }; | ||
| 27 | |||
| 28 | $RE{uint} = { | ||
| 29 | 1 | summary => 'Non-negative integer number', | |
| 30 | pat => qr/[+]?[0-9]+/, | ||
| 31 | examples => [ | ||
| 32 | {str=>'', anchor=>1, matches=>0}, | ||
| 33 | {str=>'0', anchor=>1, matches=>1}, | ||
| 34 | {str=>'+0', anchor=>1, matches=>1}, | ||
| 35 | {str=>'-0', anchor=>1, matches=>0}, | ||
| 36 | {str=>'123', anchor=>1, matches=>1}, | ||
| 37 | {str=>'+123', anchor=>1, matches=>1}, | ||
| 38 | {str=>'-123', anchor=>1, matches=>0}, | ||
| 39 | {str=>'123.1', anchor=>1, matches=>0}, | ||
| 40 | {str=>'1e2', anchor=>1, matches=>0}, | ||
| 41 | ], | ||
| 42 | }; | ||
| 43 | |||
| 44 | $RE{negint} = { | ||
| 45 | 1 | summary => 'Negative integer number', | |
| 46 | pat => qr/-[1-9][0-9]*/, | ||
| 47 | examples => [ | ||
| 48 | {str=>'', anchor=>1, matches=>0}, | ||
| 49 | {str=>'0', anchor=>1, matches=>0}, | ||
| 50 | {str=>'+0', anchor=>1, matches=>0}, | ||
| 51 | {str=>'-0', anchor=>1, matches=>0}, | ||
| 52 | |||
| 53 | {str=>'123', anchor=>1, matches=>0}, | ||
| 54 | {str=>'+123', anchor=>1, matches=>0}, | ||
| 55 | {str=>'-1', anchor=>1, matches=>1}, | ||
| 56 | #{str=>'-001', anchor=>1, matches=>0}, # currently we forbid zero prefix | ||
| 57 | {str=>'-123', anchor=>1, matches=>1}, | ||
| 58 | {str=>'-123.1', anchor=>1, matches=>0}, | ||
| 59 | {str=>'-1e2', anchor=>1, matches=>0}, | ||
| 60 | ], | ||
| 61 | }; | ||
| 62 | |||
| 63 | $RE{posint} = { | ||
| 64 | 1 | summary => 'Positive integer number', | |
| 65 | pat => qr/[+]?[1-9][0-9]*/, | ||
| 66 | examples => [ | ||
| 67 | {str=>'', anchor=>1, matches=>0}, | ||
| 68 | {str=>'0', anchor=>1, matches=>0}, | ||
| 69 | {str=>'+0', anchor=>1, matches=>0}, | ||
| 70 | {str=>'-0', anchor=>1, matches=>0}, | ||
| 71 | |||
| 72 | {str=>'1', anchor=>1, matches=>1}, | ||
| 73 | {str=>'123', anchor=>1, matches=>1}, | ||
| 74 | {str=>'+123', anchor=>1, matches=>1}, | ||
| 75 | {str=>'-1', anchor=>1, matches=>0}, | ||
| 76 | #{str=>'+001', anchor=>1, matches=>0}, # currently we forbid zero prefix | ||
| 77 | {str=>'-123', anchor=>1, matches=>0}, | ||
| 78 | {str=>'123.1', anchor=>1, matches=>0}, | ||
| 79 | {str=>'1e2', anchor=>1, matches=>0}, | ||
| 80 | ], | ||
| 81 | }; | ||
| 82 | |||
| 83 | 1 | 1; | |
| 84 | # ABSTRACT: Regexp patterns related to integers | ||
| 85 | |||
| 86 | __END__ | ||