The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Module::Generic::RegexpCapture - A Regexp Result Object

SYNOPSIS

    if( my $rv = $s->replace( qr/[[:blank:]\h]+/, '_' ) )
    {
        my $first_match = $rv->capture->first;
        # Do something
    }

VERSION

    v0.1.0

DESCRIPTION

This is a regular expression result object class. It makes it possible to execute regular expression using chaining and retrieve capture group later from this class object.

METHODS

capture

This returns an array object (Module::Generic::Array) of capture groups equivalent to @{^CAPTURE}

You can get the equivalent of $1 with:

    $re->capture->first;
    # or
    $re->capture->get(0);

$2 with

    $re->capture->second;
    # or
    $re->capture->get(1);
    # etc...

matched

Returns an integer value representing the number of successful match in the regular expression. It is equivalent to doing:

    my $n = $string =~ s/[[:blank:]\h]+//gs;

$n would contain the same value as $re->matched

name

If the regular expression was using named captures, such as

    qr/(?<my_name>.*?)/

This method will return an object whose methods are named after each named capture. For example, using the case above:

    my $str = $re->name->my_name;

result

Returns an array object (Module::Generic::Array) of returned values from the regular expression. This is equivalent to:

    my @result = $string =~ s/[[:blank:]\h]+//gs;

Note that "result" can return an array object with one empty entry. This is what perl returns in list context when there is no match. If you want to check whether your regular expression matched or not, use "matched" instead.

SEE ALSO

"like" in Module::Generic::Scalar, "match" in Module::Generic::Scalar, "replace" in Module::Generic::Scalar

AUTHOR

Jacques Deguest <jack@deguest.jp>

COPYRIGHT & LICENSE

Copyright (c) 2021 DEGUEST Pte. Ltd.

You can use, copy, modify and redistribute this package and associated files under the same terms as Perl itself.