Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Think about Loose Coupling
 
PerlMonks  

Re: pattern sequence dispersed within text

by choroba (Abbot)
on Oct 01, 2012 at 11:41 UTC ( #996626=note: print w/ replies, xml ) Need Help??


in reply to pattern sequence dispersed within text

This should do what you want:

#!/usr/bin/perl use warnings; use strict; use feature 'say'; my $word = 'helen'; my $input = 'xxxhexxxxxxxx xle xxnxle nxxx xxnxxx xnxxhexx nxxxxx xlex +xxxxx nxnx xxxx'; my $regex = '([^ \b]*' . join('[^ \b]*).*?([^ \b]*', $word =~ /(..?)/g +) . '[^ \b]*)'; my @matches = $input =~ /$regex/g; say for @matches;
The regex is constructed from the $word dynamically, so you do not have to know the length of it in advance.
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re: pattern sequence dispersed within text
Download Code
Re^2: pattern sequence dispersed within text
by Anonymous Monk on Oct 01, 2012 at 11:53 UTC
    Just in case quotemeta insert  map { "\Q$_\E" }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://996626]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2014-04-18 04:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (461 votes), past polls