Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Just another Perl shrine
 
PerlMonks  

Re: Regexp string concat

by CombatSquirrel (Hermit)
on Jun 14, 2004 at 13:37 UTC ( [id://366634]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Regexp string concat

I hacked this piece of code together. It may work for you or it may not. I think it is pretty straightforward, except for the two-level Schwartzian transform-like anonymous array nesting (Data::Dumper should help, though)...
#!perl use strict; use warnings; my $string = "EICHENBAUMSCHULE"; my @query = qw/EIC BAUM UMS CHU LE/; @query = sort { $a->[1] <=> $b->[1] || $a->[2] <=> $b->[2] } grep { $_->[1] > -1 } map { [$_, index($string, $_), index($string, $_) + length($ +_) - 1] } @query; my @matches; @query or die "No matches"; my $i = -1; my $p = -2; for (@query) { if ($p + 1 < $_->[1]) { ++$i; } push @{$matches[$i]}, $_; $p = $_->[2]; } @matches = sort { $b->[0] <=> $a->[0] } map { [$_->[-1]->[2] - $_->[0]->[1] + 1, $_] } @matches; print "Longest continuous match has length $matches[0]->[0]\n\n"; print "$string\n"; for (@{$matches[0]->[1]}) { print ' ' x $_->[1] . $_->[0] . "\n"; }
Hope this helped.
CombatSquirrel.
Entropy is the tendency of everything going to hell.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://366634]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.