aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2021-04-28 10:53:56 +0100
committerdrbaggy <js5@sanger.ac.uk>2021-04-28 10:53:56 +0100
commit52a191f723ab56240a9624d222c35391e95cb185 (patch)
tree78fb18f7b1eff42449bfb03abc9ae04428d6be68
parent4fb433346a210a16bc92a7f1f3c7749d69eb502b (diff)
downloadperlweeklychallenge-club-52a191f723ab56240a9624d222c35391e95cb185.tar.gz
perlweeklychallenge-club-52a191f723ab56240a9624d222c35391e95cb185.tar.bz2
perlweeklychallenge-club-52a191f723ab56240a9624d222c35391e95cb185.zip
expand out and comment on regex
-rw-r--r--challenge-110/james-smith/perl/ch-1.pl15
1 files changed, 15 insertions, 0 deletions
diff --git a/challenge-110/james-smith/perl/ch-1.pl b/challenge-110/james-smith/perl/ch-1.pl
index f47ec05169..5435cde1b1 100644
--- a/challenge-110/james-smith/perl/ch-1.pl
+++ b/challenge-110/james-smith/perl/ch-1.pl
@@ -9,6 +9,21 @@ use Test::More;
print grep { is_valid_phone_number($_) } <>;
sub is_valid_phone_number {
+ return m{\A # Start of line
+ \s* # Some white-space ?
+ (?: # Prefix - one of:
+ [+]\d+ | # +{digits}
+ 00\d+ | # 00{digits}
+ [(]\d+[)] # ({digits})
+ )
+ \s+ # Some white-space
+ \d+ # String of numbers
+ \s* # Some white-space ?
+ \Z # End of line
+ }x;
+}
+
+sub is_valid_phone_number_compact {
return m{\A\s*(?:[+]\d+|00\d+|[(]\d+[)])\s+\d+\s*\Z};
}