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

Re: Empty regex

Thread Previous | Thread Next
Yitzchak Scott-Thoennes
June 18, 2008 23:04
Re: Empty regex
Message ID:
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'

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

            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).

            If the pattern evaluates to the empty string, the last
            successfully executed regular expression is used instead.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About