<div dir="ltr"><div><div><div><div><div>say 'foo,bar,baz' =~ /(?:^|,)(foo)(,|$)/<br></div>> foo<br><div>say 'bar,foo,baz' =~ /(?:^|,)(foo)(,|$)/<br></div>> foo<br><div>say 'bar,baz,foo' =~ /(?:^|,)(foo)(,|$)/<br>
</div>> foo<br><br></div>The regex is generally cleaner if you use \b instead of the other bits, assuming that meets your requirements.<br><br></div>(?:...) is a non-capturing group, which is useful for delimiting alternations or applying quantifiers.<br>
<br></div>It must be Monday, because everyone seems to be struggling with this. ?:^/<br><br></div>-QM<br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Apr 29, 2013 at 7:17 PM, Antonio Sun <span dir="ltr"><<a href="mailto:antoniosun@lavabit.com" target="_blank">antoniosun@lavabit.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">that'll match cases like, <div><br></div><div><span style="font-family:Calibri;font-size:16px">bar,and foo etc,baz</span><br>
<div><br><div class="gmail_extra">I'm still think my answer is the closest, given what's required in OP.</div><div><div class="h5">
<div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Apr 29, 2013 at 2:00 PM, Stuart Watt <span dir="ltr"><<a href="mailto:stuart@morungos.com" target="_blank">stuart@morungos.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word">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. <div>

<br></div><div>All the best</div><div>Stuart</div><div><br></div><div><br><div><div><div><div>On 2013-04-29, at 1:52 PM, Indy Singh wrote:</div><br></div></div><blockquote type="cite"><div><div>
<div dir="ltr">
<div dir="ltr">
<div style="font-size:12pt;font-family:Calibri">
<div>Hi All,</div>
<div> </div>
<div>Following Alans suggestion, I am going to repost the question with some 
test cases.</div>
<div> </div>
<div>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.<br><br>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?</div>
<div> </div>
<div>Test code below. Anywhere where ‘foo’ appears should match but ‘food’ 
should not match</div>
<div> </div>
<div>foreach $s ('foo,bar,baz', 'bar,foo,baz', 'bar,baz,foo', 'bar,food,baz') 
{<br>    print "s=$s ";</div>
<div> </div>
<div>    my ($match) = $s =~ /some reg expression or perl code 
here to match foo/;</div>
<div> </div>
<div>    if ($match) 
{<br>        print 
"match=$match\n";<br>    } else 
{<br>        print "no 
match\n";<br>    }<br>}</div>
<div> </div>
<div> </div>
<div style="font-size:12pt;font-family:Calibri">Indy 
Singh<br>IndigoSTAR Software -- 
<a href="http://www.indigostar.com" target="_blank">www.indigostar.com</a></div></div></div></div></div></div>
_______________________________________________<br>toronto-pm mailing list<br><a href="mailto:toronto-pm@pm.org" target="_blank">toronto-pm@pm.org</a><br><a href="http://mail.pm.org/mailman/listinfo/toronto-pm" target="_blank">http://mail.pm.org/mailman/listinfo/toronto-pm</a><br>

</blockquote></div><br></div></div><br>_______________________________________________<br>
toronto-pm mailing list<br>
<a href="mailto:toronto-pm@pm.org" target="_blank">toronto-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/toronto-pm" target="_blank">http://mail.pm.org/mailman/listinfo/toronto-pm</a><br>
<br></blockquote></div><br></div></div></div></div></div></div>
<br>_______________________________________________<br>
toronto-pm mailing list<br>
<a href="mailto:toronto-pm@pm.org">toronto-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/toronto-pm" target="_blank">http://mail.pm.org/mailman/listinfo/toronto-pm</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>-QM<br>Quantum Mechanics: The dreams stuff is made of
</div>