Tag Archives: perl 5.10

[Perl] How to check divisibility by 3 using regular expressions

Here is a Perl regular expression using Perl 5.10 extensions (this is a finite state automaton): ^(?&s)(?(DEFINE) (?<s>([0369](?&z)|[147](?&j)|[258](?&d))) (?<z>($|[0369](?&z)|[147](?&j)|[258](?&d))) (?<j>([0369](?&j)|[147](?&d)|[258](?&z))) (?<d>([0369](?&d)|[147](?&z)|[258](?&j))))   </d></j></z></s>^(?&s)(?(DEFINE) (?<s>([0369](?&z)|[147](?&j)|[258](?&d))) (?<z>($|[0369](?&z)|[147](?&j)|[258](?&d))) (?<j>([0369](?&j)|[147](?&d)|[258](?&z))) (?<d>([0369](?&d)|[147](?&z)|[258](?&j)))) </d></j></z></s>

Posted in Perl | Tagged , , | Leave a comment