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

Re: Self-recognizing programs and regular expressions

Thread Previous | Thread Next
From:
Abigail
Date:
March 8, 2005 02:53
Subject:
Re: Self-recognizing programs and regular expressions
Message ID:
20050307235650.GF20061@abigail.nl
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:

  \A\\A\\\\A\\\\\\\\A....

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.



Abigail

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About