AidanLee has asked for the wisdom of the Perl Monks concerning the following question:
Hello all,
I was writing a little regex for a pattern i had on my hands and realized that I wasn't sure how it would wind up working. So I wrote myself a little test:
use strict; use diagnostics; while( <DATA> ) { my @list = (); if( @list = ( $_ =~ m|^rs://([-\w]+)(?:\.([-\w]+))+|) ) { print join( ' > ', @list ), "\n"; } } __DATA__ rs://a rs://b.c rs://d.e.f rs://g.h.i.j.k
so it's looking to match a pattern that is a word followed by one or more words, with periods in between them. Here's what I got back from the output:
b > c d > f g > k
I was kind of hoping it would give me back the whole
b > c d > e > f g > h > i > j > k
which is of course what split() could do for me, but i didn't see that right away. But now i'm left wondering what happened to all of the other values "in the middle" that matched. The regex seems to just have overwritten them.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex Matching Oddity
by japhy (Canon) on Jun 27, 2001 at 21:55 UTC | |
by AidanLee (Chaplain) on Jun 27, 2001 at 22:01 UTC | |
by japhy (Canon) on Jun 27, 2001 at 22:08 UTC | |
|
Re: Regex Matching Oddity
by jwest (Friar) on Jun 27, 2001 at 21:38 UTC | |
|
Re: Regex Matching Oddity
by petral (Curate) on Jun 27, 2001 at 22:00 UTC | |
by AidanLee (Chaplain) on Jun 27, 2001 at 22:07 UTC | |
|
Re: Regex Matching Oddity
by suaveant (Parson) on Jun 27, 2001 at 22:04 UTC | |
|
Re: Regex Matching Oddity
by Anonymous Monk on Jun 27, 2001 at 21:25 UTC | |
|
Re: Regex Matching Oddity
by AidanLee (Chaplain) on Jul 25, 2001 at 01:12 UTC |