Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: pattern sequence dispersed within text

by choroba (Canon)
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
Replies are listed 'Best First'.
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 about the Monastery: (18)
As of 2015-07-07 17:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls