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

Antonio Sun antoniosun at lavabit.com
Mon Apr 29 11:17:53 PDT 2013


that'll match cases like,

bar,and foo etc,baz

I'm still think my answer is the closest, given what's required in OP.


On Mon, Apr 29, 2013 at 2:00 PM, Stuart Watt <stuart at morungos.com> wrote:

> I've used \b for this. i.e., /\bfoo\b/ - the \b is a zero-width
> word/nonword boundary, and I use it a lot to anchor at separators.
>
> All the best
> Stuart
>
>
> On 2013-04-29, at 1:52 PM, Indy Singh wrote:
>
>   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
> _______________________________________________
> toronto-pm mailing list
> toronto-pm at pm.org
> http://mail.pm.org/mailman/listinfo/toronto-pm
>
>
>
> _______________________________________________
> toronto-pm mailing list
> toronto-pm at pm.org
> http://mail.pm.org/mailman/listinfo/toronto-pm
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20130429/4e57dffd/attachment-0001.html>


More information about the toronto-pm mailing list