in reply to pattern sequence dispersed within text
This should do what you want:
The regex is constructed from the $word dynamically, so you do not have to know the length of it in advance.#!/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;
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: pattern sequence dispersed within text
by Anonymous Monk on Oct 01, 2012 at 11:53 UTC |
In Section
Seekers of Perl Wisdom