develooper Front page | perl.perl5.porters | Postings from June 2008

Re: Empty regex

Thread Previous | Thread Next
From:
Yitzchak Scott-Thoennes
Date:
June 18, 2008 23:04
Subject:
Re: Empty regex
Message ID:
49293.63.231.49.141.1213855449.squirrel@webmail.efn.org
On Wed, June 18, 2008 10:56 pm, Ævar Arnfjörð Bjarmason wrote:
> // is the empty or NOTHING pattern, it matches everything because
> everything contains a bit of nothing:) split is special cased so it'll
> match nothing at position 0, internally advance the match position, match
> again at position 1 and so forth.

No, that is a feature of regexes in general, not an exception in split.
For instance:

$ perl -wle'$_="abcde"; print pos while //g'
0
1
2
3
4
5

But the OP's problem is not with // matching everywhere, it's with it not
matching everywhere, in accordance with perlop:

    m/PATTERN/cgimosx
            If the PATTERN evaluates to the empty string, the last
            *successfully* matched regular expression is used instead. In
            this case, only the "g" and "c" flags on the empty pattern is
            honoured - the other flags are taken from the original pattern.
            If no match has previously succeeded, this will (silently) act
            instead as a genuine empty pattern (which will always match).

    s/PATTERN/REPLACEMENT/egimosx
            If the pattern evaluates to the empty string, the last
            successfully executed regular expression is used instead.



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About