[tpm] String matching at start or middle or end of list
Antonio Sun
antoniosun at lavabit.com
Mon Apr 29 08:36:56 PDT 2013
On Mon, Apr 29, 2013 at 11:18 AM, J. Bobby Lopez <jbl at jbldata.com> wrote:
> Would this work for your purposes?:
>
> my $s = 'foo,bar,boo,baz';
> my ($match) = $s =~ /[,]*foo[,]*/;
That'd cast the net too wide for thing like: ' foobar,'
I am looking to match the following:
>
> The start of a string or a separator followed by
> A specified string followed by
> A separator or the end of the string
>
>
> I want to extract the matched string into a variable.
How about doing it separately:
$s =~ /^(foo),|,(foo),|,(foo)$/;
my ($match) = $1;
HTH
Antonio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20130429/81952b05/attachment-0001.html>
More information about the toronto-pm
mailing list