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

Indy Singh indy at indigostar.com
Mon Apr 29 10:52:34 PDT 2013


Hi All,

Following Alans suggestion, I am going to repost the question with some test cases.

I am looking for a way to match a string that appears in a comma separated list. The string may may appear at the start or middle, end or nowhere on a list. I have stumbled along and made this work in the past, now I am looking for the clean and proper way to do it.

One of the unpleasant side effects of putting a list with alternatives at the start .e.g. '(^|,)' , is that it creates an undesired capture string. Is it possible to avoid creating the capture string?

Test code below. Anywhere where ‘foo’ appears should match but ‘food’ should not match

foreach $s ('foo,bar,baz', 'bar,foo,baz', 'bar,baz,foo', 'bar,food,baz') {
    print "s=$s ";

    my ($match) = $s =~ /some reg expression or perl code here to match foo/;

    if ($match) {
        print "match=$match\n";
    } else {
        print "no match\n";
    }
}


Indy Singh
IndigoSTAR Software -- www.indigostar.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20130429/eb72626c/attachment.html>


More information about the toronto-pm mailing list