Finding the intersection between two regexes

Abigail abigail at abigail.be
Fri Apr 25 06:38:55 BST 2014


On Fri, Apr 25, 2014 at 12:47:04AM +0100, David Cantrell wrote:
> On 24/04/2014 23:28, Mark Fowler wrote:
>> On Thursday, April 24, 2014, Michael Lush <mjlush at gmail.com> wrote:
>>
>>      if ($x =~ /^246[2-9]\d{6}$/ and  $x =~
>>> /^246(?:(?:2[346]|45|82)\d|25[0-4])\d{4}$/ )
>>
>> Those /d are incorrect. You want [0-9] or to use the /a regexp flag on a
>> suitably modern perl.
>
> https://code.google.com/p/libphonenumber/source/browse/trunk/resources/PhoneNumberMetadata.xml
>
> My regexes come directly from Google's libphonenumber. They are happy to  
> accept patches provided you sign your life away in blood. I require no  
> such blood sacrifice for my code, but do insist that the tests still  
> pass on perl 5.8.8.
>
> https://github.com/DrHyde/perl-modules-Number-Phone
>
> Assuming that you actually care, and aren't just pedanting in the finest  
> custom of this august group, of course :-)


I'm with Mark. My view is that a /\d/ is almost always wrong, on any perl
released in this century.

/\d/a or /(?a:\d)/ is just a really ugly and confusing way to write /[0-9]/.
I bet most Perl programmers [1] won't know what /a does, let alone know the
difference between /a and /aa.



[1] Assuming developers at $WORK are a representative sample.



Abigail


More information about the london.pm mailing list