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

Shlomi Fish shlomif at shlomifish.org
Mon Apr 29 09:12:16 PDT 2013


Hi,

On Mon, 29 Apr 2013 11:14:18 -0400 Matthew Phillips <mattp at cpan.org> wrote:

> Hi,
> Maybe 'if ('foo,bar,boo,baz' =~ /,?foo,?/) { ... } ' is what you're looking
> for.

That's effectively equivalent to to «=~ /foo/» which will also match against
the string "matchmefoobar,hello,there". You want:

[QUOTE]

shlomif at telaviv1:~$ perl -dE 24

Loading DB routines from perl5db.pl version 1.37
Editor support available.

Enter h or 'h h' for help, or 'man perldebug' for more help.

main::(-e:1):   24
  DB<264> x ('foo,bar,boo,baz' =~ /(?:\A|,)foo(?:,|\z)/)
0  1
  DB<265> x (('foo,bar,boo,baz' =~ /(?:\A|,)foo(?:,|\z)/) ? "Y" : "N")
0  'Y'
  DB<266> x (('foop,bar,boo,baz' =~ /(?:\A|,)foo(?:,|\z)/) ? "Y" : "N")
0  'N'
  DB<267> x (('foo,bar,boo,baz' =~ /(?:\A|,)foo(?:,|\z)/) ? "Y" : "N")
0  'Y'
  DB<268> x (('fop,bar,boo,baz' =~ /(?:\A|,)foo(?:,|\z)/) ? "Y" : "N")
0  'N'
  DB<269> x (('fop,bar,foo,baz' =~ /(?:\A|,)foo(?:,|\z)/) ? "Y" : "N")
0  'Y'
  DB<270> x (('fop,bar,baam,foo' =~ /(?:\A|,)foo(?:,|\z)/) ? "Y" : "N")
0  'Y'
  DB<271> x (('fop,bar,foorty,baz' =~ /(?:\A|,)foo(?:,|\z)/) ? "Y" : "N")
0  'N'
  DB<272> 

[/QUOTE]

Regards,

	Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Why I Love Perl - http://shlom.in/joy-of-perl

Larry Wall is lazy, impatient and full of hubris.

Please reply to list if it's a mailing list post - http://shlom.in/reply .


More information about the toronto-pm mailing list