develooper Front page | perl.fwp | Postings from March 2005

Re: Self-recognizing programs and regular expressions

Thread Previous | Thread Next
March 8, 2005 02:53
Re: Self-recognizing programs and regular expressions
Message ID:
On Mon, Mar 07, 2005 at 11:05:15PM +0000, Ton Hospel wrote:
> Ah, the idea seems salvagable, but less elegant:
> this sequence is self matching:
> ^
> ^\^
> ^\^\\\^
> ^\^\\\^\\\\\\\^
> ....
> so an infinite sequence of ^ with 2**n-1 \ after the n-th ^

This is also self matching:


with 2**(n-1) \s before the n-th A.

Years ago, while I was still writing JAPHs, I was looking for a regex
matching itself - and nothing but itself (regexes that match themselves,
and also other strings are easy and IMO, not interesting), but I never
found one. The search wasn't entirely fruitless, it did lead to:

       my $qr =  qr/^.+?(;).+?\1|;Just another Perl Hacker;|;.+$/;
          $qr =~  s/$qr//g;
    print $qr, "\n";

But that's a far cry from what I wanted to find.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About