Module:...Capture(3)

πŸ“¦ version 1.1.3, in alpine 3.24

πŸ’… NAME πŸ’…

Okay so bestie, this is Module::Generic::RegexpCapture β€” it's a Regexp Result Object, and it's literally the little cutie that holds your regex results so you can go back and grab them whenever. No cap. (Also hi, this is from the User Contributed Perl Documentation, and the page header says Module:...Capture(3) β€” iykyk.)


✨ SYNOPSIS ✨

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

See that? $rv->capture->first β€” chaining is the whole vibe here πŸ¦‹


πŸŽ€ VERSION πŸŽ€

    v0.1.0

🌸 DESCRIPTION 🌸

So this is a regular expression result object class, periodt. The way it works: it lets you run a regular expression using chaining, and then later you can pull out your capture groups from this class object. It's giving "hold my results so I don't have to think about them right now" energy πŸ’–


πŸ‘‘ METHODS πŸ‘‘

πŸ’« capture

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

Want the equivalent of $1? Easy:

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

And $2:

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

Literally so convenient, ngl πŸ”₯

πŸ’« matched

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

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

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

πŸ’« name

If your regular expression was using named captures, such as

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

then 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;

Named captures really said "I'll be the main character" πŸ’…

πŸ’« 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;
🚨 Okay important thing bestie, listen up: result can return an array object with one empty entry. That's just what perl returns in list context when there is no match. So if you actually want to check whether your regular expression matched or not, use matched instead. Fr fr, don't get caught out by this one 😭

πŸ¦‹ SEE ALSO πŸ¦‹

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

Go read those too, they're iconic ✨


πŸ™ˆ AUTHOR πŸ™ˆ

Jacques Deguest <jack@deguest.jp>


Copyright (c) 2021-2024 DEGUEST Pte. Ltd.

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


Okay that's the whole page, you ate that πŸ’œ

Sign-off time: this lovely little doc is running on perl v5.42.2, dated 2026-02-15, and it's Module:...Capture(3) all the way down. Byeee πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from