[tpm] String matching at start or middle or end of list

Shlomi Fish shlomif at shlomifish.org
Mon Apr 29 09:16:31 PDT 2013


Hi Antonio,

On Mon, 29 Apr 2013 11:36:56 -0400
Antonio Sun <antoniosun at lavabit.com> wrote:

> 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;

1. This won't match if foo is the second or third capture.

2. What happens if $s eq 'foo' (and contains no commas)? See my response for
more information.

Regards,

	Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
What does "Zionism" mean? - http://shlom.in/def-zionism

Satan condemned Hitler for a million years of writing XSLT.
    — http://www.shlomifish.org/humour/bits/facts/XSLT/

Please reply to list if it's a mailing list post - http://shlom.in/reply .


More information about the toronto-pm mailing list