From: kj on



Is there a way to tell if a given Regexp object, generated at
runtime, includes at least one pair of capture parentheses?

More generally, is there any documentation for the Regexp class?
(I'm referring to the class alluded to by the output of, e.g., ref
qr//). Running perldoc Regexp fails ("no docs found"), and perldoc
perlre does not say much at all about this class as such.

TIA!

Kynn
From: C.DeRykus on
On Jan 22, 9:54 am, kj <no.em...(a)please.post> wrote:
> Is there a way to tell if a given Regexp object, generated at
> runtime, includes at least one pair of capture parentheses?
>
> More generally, is there any documentation for the Regexp class?
> (I'm referring to the class alluded to by the output of, e.g., ref
> qr//).  Running perldoc Regexp fails ("no docs found"), and perldoc
> perlre does not say much at all about this class as such.
>

perldoc perlop (see: Regexp Quote-Like Operators)

The regex object is viewable as a string:

$ perl -le '$regex = qr/ab(\d+)/; print $regex'
(?-xism:ab(\d+))

--
Charles DeRykus

From: Ben Morrow on

Quoth kj <no.email(a)please.post>:
>
> Is there a way to tell if a given Regexp object, generated at
> runtime, includes at least one pair of capture parentheses?
>
> More generally, is there any documentation for the Regexp class?
> (I'm referring to the class alluded to by the output of, e.g., ref
> qr//). Running perldoc Regexp fails ("no docs found"), and perldoc
> perlre does not say much at all about this class as such.

The Regexp 'class' doesn't have any methods[1], and isn't really useable
as a class at all. In Perl 5.12 it will be mostly replaced by a new
REGEXP svtype, which was what it should have been from the beginning.
(qr// will still return a ref blessed into Regexp, for compatibility.)

Ben

[1] Well, it has a completely empty DESTROY method, because not having
one caused a problem somewhere.

From: Ilya Zakharevich on
On 2010-01-22, Ben Morrow <ben(a)morrow.me.uk> wrote:
> The Regexp 'class' doesn't have any methods[1], and isn't really useable
> as a class at all. In Perl 5.12 it will be mostly replaced by a new
> REGEXP svtype, which was what it should have been from the beginning.
> (qr// will still return a ref blessed into Regexp, for compatibility.)

Is there any way to find that an object is of a REGEXP svtype (without
using overload::StrVal)? Without this, serialization is not possible;
witness failure of FreezeThaw...

Or, at least, get hints that it "might be REGEXP" (with no false
negatives), so that a call to overload::StrVal() is needed...

Yours,
Ilya
From: Ben Morrow on

Quoth Ilya Zakharevich <nospam-abuse(a)ilyaz.org>:
> On 2010-01-22, Ben Morrow <ben(a)morrow.me.uk> wrote:
> > The Regexp 'class' doesn't have any methods[1], and isn't really useable
> > as a class at all. In Perl 5.12 it will be mostly replaced by a new
> > REGEXP svtype, which was what it should have been from the beginning.
> > (qr// will still return a ref blessed into Regexp, for compatibility.)
>
> Is there any way to find that an object is of a REGEXP svtype (without
> using overload::StrVal)? Without this, serialization is not possible;
> witness failure of FreezeThaw...
>
> Or, at least, get hints that it "might be REGEXP" (with no false
> negatives), so that a call to overload::StrVal() is needed...

As of 5.10, re::is_regexp will reliably identify a compiled regex,
regardless of reblessing or overloading. Under 5.10 it looks for a ref
to a scalar with 'r' magic (but correctly ignores the weird 'r' magic
used by /(??{})/), under 5.12 it will look for a REGEXP or a ref to a
REGEXP.

I don't think re is dual-life, so this isn't portable to pre-5.10,
though presumably it could be emulated with B if necessary.

Ben