Regular Expression to check for primes

perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/' [number]

<div class="posterous_quote_citation">
  via <a href="http://montreal.pm.org/tech/neil_kandalgaonkar.shtml">montreal.pm.org</a>
</div>

<p>
  This is a nice trick to check if a number is prime using regular expressions, I am going to try and see how this performs compared to regular methods and see if anything interesting comes up.
</p>

Posted via email from Sijin Joseph

Sijin Joseph
Sijin Joseph

Hands-on technology leader with 15+ yrs of experience in launching products, scaling up teams and setting up software infrastructure.