(cartman impersonation) swweeeet.
-----Original Message-----
From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 07, 2002 11:01 AM
To: Nikola Janceski
Cc: Beginners (E-mail)
Subject: Re: Long shot on possibly existent pattern matching module?
On Mar 7, Nikola Janceski said:
>I was wondering if there is a module out there that will find a the common
>pattern among an array of strings and return the regular expression to
match
>the common part.
It's not going to be "fun", but it can be done:
sub longest_common_substr {
# provided you know there are no NULs
my $str = join "\0", @_;
my $rep = @_ - 1;
my $len = 1;
my $match;
$len = length($match = $1) + 1
while $str =~ m{
(?=
([^\0]{$len,})
(?: [^\0]* \0 [^\0]*? \1 ){$rep}
)
}xg;
return $match;
}
>@stuff = qw (123crapstuff morecrap crappedshit);
print longest_common_substr(@stuff); # "crap"
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
----------------------------------------------------------------------------
--------------------
The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]