<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">You'd have to use () to get the
back-reference, so using Mike's suggestion it would be:<br>
<br>
-------<br>
use feature say;<br>
my $s = 'foo,bar,boo,baz';<br>
my $match;<br>
<br>
if ( ($match) = 'foo,bar,boo,baz' =~ /,?(foo),?/) { say $match } <br>
-------<br>
<br>
Or mine..<br>
<br>
-------<br>
use feature say;<br>
my $s = 'foo,bar,boo,baz';<br>
my $match;<br>
<br>
if ( ($match) = 'foo,bar,boo,baz' =~ /[,]*(foo)[,]*/) { say $match
} <br>
-------<br>
<br>
<br>
Unless of course I'm missing some other requirement/restriction.<br>
<br>
<br>
<br>
On 13-04-29 11:18 AM, Indy Singh wrote:<br>
</div>
<blockquote cite="mid:415EED0C6E614DC0A15A27281A4B274B@indy"
type="cite">
<div dir="ltr">
<div style="FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE:
12pt">
<div>I want to extract the matched string into a variable.</div>
<div> </div>
<div>e.g.</div>
<div>my ($match) = something</div>
<div> </div>
<div> </div>
<div style="FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE:
12pt">Indy Singh<br>
IndigoSTAR Software -- <a class="moz-txt-link-abbreviated" href="http://www.indigostar.com">www.indigostar.com</a></div>
<div style="FONT-STYLE: normal; DISPLAY: inline; FONT-FAMILY:
'Calibri'; COLOR: #000000; FONT-SIZE: small; FONT-WEIGHT:
normal; TEXT-DECORATION: none">
<div style="FONT: 10pt tahoma">
<div> </div>
<div style="BACKGROUND: #f5f5f5">
<div style="font-color: black"><b>From:</b> <a
moz-do-not-send="true" title="mattp@cpan.org"
href="mailto:mattp@cpan.org">Matthew Phillips</a> </div>
<div><b>Sent:</b> Monday, April 29, 2013 11:14 AM</div>
<div><b>To:</b> <a moz-do-not-send="true"
title="indy@indigostar.com"
href="mailto:indy@indigostar.com">Indy Singh</a> </div>
<div><b>Cc:</b> <a moz-do-not-send="true"
title="toronto-pm@pm.org"
href="mailto:toronto-pm@pm.org">Toronto PerlMongers</a>
</div>
<div><b>Subject:</b> Re: [tpm] String matching at start
or middle or end of list</div>
</div>
</div>
<div> </div>
</div>
<div style="FONT-STYLE: normal; DISPLAY: inline; FONT-FAMILY:
'Calibri'; COLOR: #000000; FONT-SIZE: small; FONT-WEIGHT:
normal; TEXT-DECORATION: none">Hi,<br>
Maybe 'if ('foo,bar,boo,baz' =~ /,?foo,?/) { ... } ' is what
you're looking for.<br>
<br>
Cheers,<br>
Matt<br>
<br>
<div class="gmail_quote">On Mon, Apr 29, 2013 at 11:09 AM,
Indy Singh <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:indy@indigostar.com" target="_blank">indy@indigostar.com</a>></span>
wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN:
0px 0px 0px 0.8ex; PADDING-LEFT: 1ex"
class="gmail_quote">Hi All,<br>
<br>
What is a good way to match a string that may appear at
the start or middle or end of 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>
<br>
Example:<br>
my $s = 'foo,bar,boo,baz';<br>
my ($match) = $s =~ /(foo)/;<br>
<br>
I am looking to match the following:<br>
The start of a string or a separator followed by<br>
A specified string followed by<br>
A separator or the end of the string<br>
<br>
What are the extra things I need to surround the match
expression?<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?<br>
<br>
Indy Singh<br>
IndigoSTAR Software -- <a moz-do-not-send="true"
href="http://www.indigostar.com" target="_blank">www.indigostar.com</a><br>
<br>
_______________________________________________<br>
toronto-pm mailing list<br>
<a moz-do-not-send="true"
href="mailto:toronto-pm@pm.org" target="_blank">toronto-pm@pm.org</a><br>
<a moz-do-not-send="true"
href="http://mail.pm.org/mailman/listinfo/toronto-pm"
target="_blank">http://mail.pm.org/mailman/listinfo/toronto-pm</a><br>
</blockquote>
</div>
<div> </div>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
toronto-pm mailing list
<a class="moz-txt-link-abbreviated" href="mailto:toronto-pm@pm.org">toronto-pm@pm.org</a>
<a class="moz-txt-link-freetext" href="http://mail.pm.org/mailman/listinfo/toronto-pm">http://mail.pm.org/mailman/listinfo/toronto-pm</a>
</pre>
</blockquote>
<br>
</body>
</html>