in reply to Regex and loop question
should in my eyes work if $string contained the contents of the text field.#!perl use strict; use warnings; my $string = "I don't know what to do ** when I do this"; if ($string =~ /(.*?\*\*.*?)(\b[a-zA-Z']+\b)/) { print "Match <$2> at offset " . length($1) . $/; } else { print "No match" . $/; } my @chars = (split //, $2); @chars = @chars[0..9] if (@chars > 10); print join(' - ', @chars) . $/; __END__ OUTPUT: Match <when> at offset 27 w - h - e - n
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Regex and loop question
by perl_seeker (Scribe) on Aug 22, 2003 at 10:18 UTC |