Name

SPVM::Regex::Match - Regex Matching Result

Description

The Regex::Match class of SPVM has methods to manipulate a regex matching result.

Usage

use Regex::Match;

my $match = Regex::Match->new({success => 1, captures => [(string)"abc", "def"]});

my $cap1 = $match->cap1;
my $cap2 = $match->cap2;
my $cpa3 = $match->cap3;

Fields

success

has success : ro byte;

Gets the success field.

If a pattern match is successful, this field is set to 1.

captures

has captures : string[];

Gets the captures field.

The captured strings.

method captures : string ($index : int);

The captures method is the method to get an element of the captures field.

The length of the captures field can be got by the "captures_length" method.

match_start

has match_start : ro int;

Gets the match_start field.

The start offset of the matched string.

match_length

has match_length : ro int;

Gets the match_length field.

The length of the matched string.

Class Methods

new

static method new : Regex::Match ($options : object[] = undef);

Creates a new Regex::Match object.

Options:

The options are key-value pairs.

Each key must be a string type. Otherwise an exception is thrown.

If an unsupported option is specified, an exception is thrown.

  • success

    Sets the success field.

    This option must be cast to a Int object. Otherwise an exception is thrown.

  • match_start

    Sets the match_start field.

    This option must be cast to a Int object. Otherwise an exception is thrown.

  • match_length

    Sets the match_length field.

    This option must be cast to a Int object. Otherwise an exception is thrown.

  • captures

    Sets the captures field.

    A new string array with the same length of this option is created and the address of each string is copied.

    This option must be cast to a string[] object. Otherwise an exception is thrown.

Examples:

my $match = Regex::Match->new({success => 1, captures => [(string)"abc", "def"]});

Instance Methods

captures_length

method captures_length : int ();

Gets the length of the "captures" field.

cap1

method cap1 : string ();

The same as the "captures" method with 1 as the argument $index.

cap2

method cap2 : string ();

The same as the "captures" method with 2 as the argument $index.

cap3

method cap3 : string ();

The same as the "captures" method with 3 as the argument $index.

cap4

method cap4 : string ();

The same as the "captures" method with 4 as the argument $index.

cap5

method cap5 : string ();

The same as the "captures" method with 5 as the argument $index.

cap6

method cap6 : string ();

The same as the "captures" method with 6 as the argument $index.

cap7

method cap7 : string ();

The same as the "captures" method with 7 as the argument $index.

cap8

method cap8 : string ();

The same as the "captures" method with 8 as the argument $index.

cap9

method cap9 : string ();

The same as the "captures" method with 9 as the argument $index.

cap10

method cap10 : string ();

The same as the "captures" method with 10 as the argument $index.

cap11

method cap11 : string ();

The same as the "captures" method with 11 as the argument $index.

cap12

method cap12 : string ();

The same as the "captures" method with 12 as the argument $index.

cap13

method cap13 : string ();

The same as the "captures" method with 13 as the argument $index.

cap14

method cap14 : string ();

The same as the "captures" method with 14 as the argument $index.

cap15

method cap15 : string ();

The same as the "captures" method with 15 as the argument $index.

cap16

method cap16 : string ();

The same as the "captures" method with 16 as the argument $index.

cap17

method cap17 : string ();

The same as the "captures" method with 17 as the argument $index.

cap18

method cap18 : string ();

The same as the "captures" method with 18 as the argument $index.

cap19

method cap19 : string ();

The same as the "captures" method with 19 as the argument $index.

cap20

method cap20 : string ();

The same as the "captures" method with 20 as the argument $index.

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License