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

J. Bobby Lopez jbl at jbldata.com
Mon Apr 29 08:54:38 PDT 2013


In that case you'll likely need to split on the delimeter [,]

On 13-04-29 11:42 AM, Indy Singh wrote:
> It still matches food. The string to match may or may not end on a 
> word boundary.
>
> -----Original Message----- From: J. Bobby Lopez Sent: Monday, April 
> 29, 2013 11:33 AM To: Indy Singh Cc: toronto-pm at pm.org Subject: Re: 
> [tpm] String matching at start or middle or end of list
> Ah, I think I got blind-sided by 'food' instead of 'foo'.  Now I'm 
> hungry.
>
>
> How about this?:
> ----
> use feature say;
> my $match;
>
> if ( ($match) = 'food,bar,boo,baz' =~ /[,]*(foo\w?)[,]*/) { say $match }
> ----
>
>
>
> On 13-04-29 11:24 AM, Indy Singh wrote:
>> This fails for the following case:
>> my $s = 'food,bar,baz';
>> my ($match) = $s =~ /[,]*(foo)[,]*/;
>> print "match=$match\n";
>>
>> In this case 'foo' matches, but is not a valid match. Only 'food' is 
>> a valid match.
>>
>>
>> Indy Singh
>> IndigoSTAR Software -- www.indigostar.com
>> -----Original Message----- From: J. Bobby Lopez Sent: Monday, April 
>> 29, 2013 11:18 AM To: toronto-pm at pm.org Subject: Re: [tpm] String 
>> matching at start or middle or end of list
>> Would this work for your purposes?:
>>
>> my $s = 'foo,bar,boo,baz';
>> my ($match) = $s =~ /[,]*foo[,]*/;
>>
>>
>> On 13-04-29 11:09 AM, Indy Singh wrote:
>>> Hi All,
>>>
>>> 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.
>>>
>>>
>>> Example:
>>> my $s = 'foo,bar,boo,baz';
>>> my ($match) = $s =~ /(foo)/;
>>>
>>> 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
>>>
>>> What are the extra things I need to surround the match expression?
>>>
>>> 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?
>>>
>>> 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
>



More information about the toronto-pm mailing list