Funny regexp: /^1?$|^(11+?)\1+$/

For the Compleat Fan
Locked
Cyril
Posts: 183
Joined: Tue Oct 30, 2007 6:27 pm
Location: Moscow, Russia
Contact:

Funny regexp: /^1?$|^(11+?)\1+$/

Post by Cyril »

I have found this funny regexp here, guess what it matches? Or check it with newLISP:

Code: Select all

(for (i 1 100)
  (unless (regex {^1?$|^(11+?)\1+$} (dup "1" i))
    (print i " ")))
Astonishing! ;-)
With newLISP you can grow your lists from the right side!

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Re: Funny regexp: /^1?$|^(11+?)\1+$/

Post by cormullion »

Cool. Someone explain it to me ... :/

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: Funny regexp: /^1?$|^(11+?)\1+$/

Post by Lutz »

There is a nice explanation here:

http://zmievski.org/2010/08/the-prime-that-wasnt

Locked