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

Re: pattern sequence dispersed within text

by choroba (Bishop)
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.
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://996626]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2018-06-18 16:01 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (110 votes). Check out past polls.