Regex::Element(3)
Bestie, welcome to the Regex::Element(3) manual page β aka YAPE::Regex::Element, User Contributed Perl Documentation. Grab a boba, because this one is long and iconic. π
π NAME π
YAPE::Regex::Element β sub-classes for YAPE::Regex elements.
β¨ VERSION β¨
This document refers to YAPE::Regex::Element version 4.00.
π SYNOPSIS π
use YAPE::Regex 'MyExt::Mod';
# this sets up inheritence in MyExt::Mod
# see YAPE::Regex documentation
π YAPE" MODULES π
okay so the whole YAPE hierarchy of modules is an attempt at a unified means of parsing and extracting content. It attempts to maintain a generic interface, to promote simplicity and reusability. The API is powerful, yet simple. The modules do tokenization (which can be intercepted) and build trees, so that extraction of specific nodes is doable. Periodt. π
π DESCRIPTION π
This module provides the classes for the YAPE::Regex objects. The base class for these objects is YAPE::Regex::Element. The objects classes are numerous. Not me saying that like it's a bad thing β it's giving expansive. π
π¦ Methods for YAPE::Regex::Element π¦
This class contains fallback methods for the other classes. It's the main character that holds it down for everyone else. π«Ά
my $str = $obj->text;β Returns a string representation of the content of the regex node itself, not any nodes contained in it. This isundeffor non-text nodes. So if you're not text, you get nothing, bestie. πmy $str = $obj->string;β Returns a string representation of the regex node itself, not any nodes contained in it.my $str = $obj->fullstring;β Returns a string representation of the regex node, including any nodes contained in it. The whole family, no cap. πmy $quant = $obj->quant;β Returns a string with the quantity, and a?if the node is non-greedy. The quantity is one of"*","+","?","{M,N}", or an empty string.my $ng = $obj->ngreed;β Returns a?if the node is non-greedy, and an empty string otherwise.
πΈ Methods for YAPE::Regex::anchor πΈ
This class represents anchors. Objects have the following methods:
my $anchor = YAPE::Regex::anchor->new($type,$q,$ng);β Creates aYAPE::Regex::anchorobject. Takes three arguments: the anchor ("^","\A","$","\Z","\z","\B","\b", or"\G"), the quantity, and the non-greedy flag. The quantity should be an empty string.
my $anc = YAPE::Regex::anchor->new('\A', '', '?');
# /\A?/
my $type = $anchor->type;β Returns the string"anchor".
π Methods for YAPE::Regex::macro π
This class represents character-class macros. Objects have the following methods:
my $macro = YAPE::Regex::macro->new($type,$q,$ng);β Creates aYAPE::Regex::macroobject. Takes three arguments: the macro ("w","W","d","D","s", or"S"), the quantity, and the non-greedy flag.
my $macro = YAPE::Regex::macro->new('s', '{3,5}');
# /\s{3,5}/
my $text = $macro->text;β Returns the macro.
print $macro->text; # '\s'
my $type = $macro->type;β Returns the string"macro".
π§ Methods for YAPE::Regex::oct π§
This class represents octal escapes. Objects have the following methods:
my $oct = YAPE::Regex::oct->new($type,$q,$ng);β Creates aYAPE::Regex::octobject. Takes three arguments: the octal number (as a string), the quantity, and the non-greedy flag.
my $oct = YAPE::Regex::oct->new('040');
# /\040/
my $text = $oct->text;β Returns the octal escape.
print $oct->text; # '\040'
my $type = $oct->type;β Returns the string"oct".
π Methods for YAPE::Regex::hex π
This class represents hexadecimal escapes. Objects have the following methods:
my $hex = YAPE::Regex::hex->new($type,$q,$ng);β Creates aYAPE::Regex::hexobject. Takes three arguments: the hexadecimal number (as a string), the quantity, and the non-greedy flag.
my $hex = YAPE::Regex::hex->new('20','{2,}');
# /\x20{2,}/
my $text = $hex->text;β Returns the hexadecimal escape.
print $hex->text; # '\x20'
my $type = $hex->type;β Returns the string"hex".
π¦ Methods for YAPE::Regex::utf8hex π¦
This class represents UTF hexadecimal escapes. Objects have the following methods:
my $hex = YAPE::Regex::utf8hex->new($type,$q,$ng);β Creates aYAPE::Regex::utf8hexobject. Takes three arguments: the hexadecimal number (as a string), the quantity, and the non-greedy flag.
my $utf8hex = YAPE::Regex::utf8hex->new('beef','{0,4}');
# /\x{beef}{2,}/
my $text = $utf8hex->text;β Returns the hexadecimal escape.
print $utf8hex->text; # '\x{beef}'
my $type = $utf8hex->type;β Returns the string"utf8hex".
π Methods for YAPE::Regex::backref π
This class represents back-references. Objects have the following methods:
my $bref = YAPE::Regex::bref->new($type,$q,$ng);β Creates aYAPE::Regex::brefobject. Takes three arguments: the number of the back-reference, the quantity, and the non-greedy flag.
my $bref = YAPE::Regex::bref->new(2,'','?');
# /\2?/
my $text = $bref->text;β Returns the backescape.
print $bref->text; # '\2'
my $type = $bref->type;β Returns the string"backref".
π Methods for YAPE::Regex::ctrl π
This class represents control character escapes. Objects have the following methods:
my $ctrl = YAPE::Regex::ctrl->new($type,$q,$ng);β Creates aYAPE::Regex::ctrlobject. Takes three arguments: the control character, the quantity, and the non-greedy flag.
my $ctrl = YAPE::Regex::ctrl->new('M');
# /\cM/
my $text = $ctrl->text;β Returns the control character escape.
print $ctrl->text; # '\cM'
my $type = $ctrl->type;β Returns the string"ctrl".
π Methods for YAPE::Regex::named π
This class represents named characters. Objects have the following methods:
my $ctrl = YAPE::Regex::named->new($type,$q,$ng);β Creates aYAPE::Regex::namedobject. Takes three arguments: the name of the character, the quantity, and the non-greedy flag.
my $named = YAPE::Regex::named->new('GREEK SMALL LETTER BETA');
# /\N{GREEK SMALL LETTER BETA}/
my $text = $named->text;β Returns the character escape text.
print $named->text; # '\N{GREEK SMALL LETTER BETA}'
my $type = $named->type;β Returns the string"named".
π Methods for YAPE::Regex::Cchar π
This class represents C characters. Objects have the following methods:
my $ctrl = YAPE::Regex::Cchar->new($q,$ng);β Creates aYAPE::Regex::Ccharobject. Takes two arguments: the quantity and the non-greedy flag.
my $named = YAPE::Regex::Char->new(2);
# /\C{2}/
my $text = $Cchar->text;β Returns the escape sequence.
print $Cchar->text; # '\C'
my $type = $Cchar->type;β Returns the string"Cchar".
π₯ Methods for YAPE::Regex::slash π₯
This class represents any other escaped characters. Objects have the following methods:
my $slash = YAPE::Regex::slash->new($type,$q,$ng);β Creates aYAPE::Regex::slashobject. Takes three arguments: the backslashed character, the quantity, and the non-greedy flag.
my $slash = YAPE::Regex::slash->new('t','','?');
# /\t?/
my $text = $slash->text;β Returns the escaped character.
print $slash->text; # '\t'
my $type = $slash->type;β Returns the string"slash".
π Methods for YAPE::Regex::any π
This class represents the dot metacharacter. Objects have the following methods:
my $any = YAPE::Regex::any->new($q,$ng);β Creates aYAPE::Regex::anyobject. Takes two arguments: the quantity, and the non-greedy flag.
my $any = YAPE::Regex::any->new('{1,3}');
# /.{1,3}/
my $type = $any->type;β Returns the string"any".
π Methods for YAPE::Regex::class π
This class represents character classes. Objects have the following methods:
my $class = YAPE::Regex::class->new($chars,$neg,$q,$ng);β Creates aYAPE::Regex::classobject. Takes four arguments: the characters in the class, a"^"if the class is negated (an empty string otherwise), the quantity, and the non-greedy flag.
my $class = YAPE::Regex::class->new('aeiouy','^');
# /[^aeiouy]/
my $text = $class->text;β Returns the character class.
print $class->text; # [^aeiouy]
my $type = $class->type;β Returns the string"class".
π Methods for YAPE::Regex::hex π
This class represents hexadecimal escapes. Objects have the following methods:
my $text = YAPE::Regex::text->new($text,$q,$ng);β Creates aYAPE::Regex::textobject. Takes three arguments: the text, the quantity, and the non-greedy flag. The quantity and non-greedy modifier should only be present for single-character text, because of the way the parser renders the quantity and non-greedy modifier.
my $text = YAPE::Regex::text->new('alphabet','');
# /alphabet/
my $text = YAPE::Regex::text->new('x','?','?');
# /x??/
my $type = $text->type;β Returns the string"text".
π¦ Methods for YAPE::Regex::alt π¦
This class represents alternation. Objects have the following methods:
my $alt = YAPE::Regex::alt->new;β Creates aYAPE::Regex::altobject.
my $alt = YAPE::Regex::alt->new;
# /|/
my $type = $oct->type;β Returns the string"alt".
π Methods for YAPE::Regex::comment π
This class represents in-line comments. Objects have the following methods:
my $comment = YAPE::Regex::comment->new($comment,$x);β Creates aYAPE::Regex::commentobject. Takes two arguments: the text of the comment, and whether or not the/xregex modifier is in effect for this comment. Note that Perl's regex engine will stop a"(?#...)"comment at the first")", regardless of what you do.
my $comment = YAPE::Regex::comment->new(
"match an optional string of digits"
);
# /(?#match an optional string of digits)/
my $comment = YAPE::Regex::comment->new(
"match an optional string of digits",
1
);
# /# match an optional string of digits/
my $type = $comment->type;β Returns the string"comment".my $x_on = $comment->xcomm;β Returns true or false, depending on whether the comment is under the/xregex modifier.
π§ Methods for YAPE::Regex::whitespace π§
This class represents whitespace under the /x regex modifier. Objects have the following methods:
my $ws = YAPE::Regex::whitespace->new($text);β spins up aYAPE::Regex::whitespaceobject. It takes one argument: the actual text of the whitespace. π
my $ws = YAPE::Regex::whitespace->new(' ');
# / /x
my $text = $ws->text;β hands you back the whitespace. that's it, that's the whole job π«Ά
print $ws->text; # ' '
my $type = $ws->type;β returns the string"whitespace".
πΈ Methods for YAPE::Regex::flags πΈ
This class is giving (?ismx) flags energy. Objects come with these methods:
my $flags = YAPE::Regex::flags->new($add,$sub);β creates aYAPE::Regex::flagsobject. Takes two arguments: a string of the modes to have on, and a string of the modes to explicitly turn off. The flags get displayed in alphabetical order, no cap. π
my $flags = YAPE::Regex::flags->new('is','m');
# /(?is-m)/
my $type = $flags->type;β returns the string"flags".
βοΈ Methods for YAPE::Regex::cut βοΈ
This class represents the cut assertion. Objects have these methods:
my $look = YAPE::Regex::cut->new(\@nodes);β creates aYAPE::Regex::cutobject. Takes one argument: a reference to an array of objects to be contained in the cut.
my $REx = YAPE::Regex::class->new('aeiouy','','+');
my $look = YAPE::Regex::cut->new(0,[$REx]);
# /(?>[aeiouy]+)/
my $type = $cut->type;β returns the string"cut".
π Methods for YAPE::Regex::lookahead π
This class represents lookaheads. Objects have these methods:
my $look = YAPE::Regex::lookahead->new($pos,\@nodes);β creates aYAPE::Regex::lookaheadobject. Takes two arguments: a boolean value saying whether or not the lookahead is positive, and a reference to an array of objects to be contained in the lookahead.
my $REx = YAPE::Regex::class->new('aeiouy');
my $look = YAPE::Regex::lookahead->new(0,[$REx]);
# /(?![aeiouy])/
my $pos = $look->pos;β returns true if the lookahead is positive.
print $look->pos ? 'pos' : 'neg'; # 'neg'
my $type = $look->type;β returns the stringlookahead(pos)orlookahead(neg).
π Methods for YAPE::Regex::lookbehind π
This class represents lookbehinds. Objects have these methods:
my $look = YAPE::Regex::lookbehind->new($pos,\@nodes);β creates aYAPE::Regex::lookbehindobject. Takes two arguments: a boolean value saying whether or not the lookbehind is positive, and a reference to an array of objects to be contained in the lookbehind.
my $REx = YAPE::Regex::class->new('aeiouy','^');
my $look = YAPE::Regex::lookbehind->new(1,[$REx]);
# /(?<=[^aeiouy])/
my $pos = $look->pos;β returns true if the lookbehind is positive.
print $look->pos ? 'pos' : 'neg'; # 'pos'
my $type = $look->type;β returns the stringlookbehind(pos)orlookbehind(neg).
β Methods for YAPE::Regex::conditional β
This class represents conditionals. Objects have these methods:
my $cond = YAPE::Regex::conditional->new($br,$t,$f,$q,$ng);β creates aYAPE::Regex::hexobject. Takes five arguments: the number of the back-reference (that's all that's supported in the current version, bestie β just the backref number), an array reference to the "true" pattern, an array reference to the "false" pattern, and the quantity and non-greedy flag.
my $cond = YAPE::Regex::conditional->new(
2,
[],
[ YAPE::Regex::text->new('foo') ],
'?',
);
# /(?(2)|foo)?/
my $br = $cond->backref;β returns the number of the back-reference that the conditional depends on.
print $br->backref; # 2
my $type = $cond->type;β returns the stringconditional(N), where N is the number of the back-reference.
π Methods for YAPE::Regex::group π
This class represents non-capturing groups. Objects have these methods:
my $group = YAPE::Regex::group->new($on,$off,\@nodes,$q,$ng);β creates aYAPE::Regex::groupobject. Takes five arguments: the modes turned on, the modes explicitly turned off, a reference to an array of objects in the group, the quantity, and the non-greedy flag. The modes get displayed in alphabetical order. β¨
my $group = YAPE::Regex::group->new(
'i',
's',
[
YAPE::Regex::macro->new('d', '{2}'),
YAPE::Regex::macro->new('s'),
YAPE::Regex::macro->new('d', '{2}'),
],
'?',
);
# /(?i-s:\d{2}\s\d{2})?/
my $type = $group->type;β returns the string"group".
π
Methods for YAPE::Regex::capture π
This class represents capturing groups. Objects have these methods:
my $capture = YAPE::Regex::capture->new(\@nodes,$q,$ng);β creates aYAPE::Regex::captureobject. Takes three arguments: a reference to an array of objects in the group, the quantity, and the non-greedy flag.
my $capture = YAPE::Regex::capture->new(
[
YAPE::Regex::macro->new('d', '{2}'),
YAPE::Regex::macro->new('s'),
YAPE::Regex::macro->new('d', '{2}'),
],
);
# /(\d{2}\s\d{2})/
my $type = $capture->type;β returns the string"capture".
π» Methods for YAPE::Regex::code π»
This class represents code blocks. Objects have these methods:
my $code = YAPE::Regex::code->new($block);β creates aYAPE::Regex::codeobject. Takes one argument: a string holding a block of code.
my $code = YAPE::Regex::code->new(q({ push @poss, $1 }));
# /(?{ push @poss, $1 })/
my $type = $code->type;β returns the string"code".
β³ Methods for YAPE::Regex::later β³
This class represents closed parentheses. Objects have these methods:
my $later = YAPE::Regex::later->new($block);β creates aYAPE::Regex::laterobject. Takes one argument: a string holding a block of code.
my $later = YAPE::Regex::later->new(q({ push @poss, $1 }));
# /(?{{ push @poss, $1 }})/
my $type = $later->type;β returns the string"later".
π Methods for YAPE::Regex::close π
This class represents closed parentheses. Objects have these methods:
my $close = YAPE::Regex::close->new($q,$ng);β creates aYAPE::Regex::closeobject. Takes two arguments: the quantity, and the non-greedy flag. ngl this object is never needed in the tree; however, they are returned in the parsing stage, so that you know when they've been reached. π«Ά
my $close = YAPE::Regex::close->new('?','?');
# /)??/
my $type = $close->type;β returns the string"close".
π TO DO π
This is a listing of things to add to future versions of this module.
- None! π slay, we're done here, nothing left on the vision board.
π BUGS π
Following is a list of known or reported bugs.
- This documentation might be incomplete. π (yes bestie, the docs about the docs being incomplete. iconic honestly.)
π«Ά SUPPORT π«Ά
Visit YAPE's web site at http://www.pobox.com/~japhy/YAPE/.
π SEE ALSO π
The YAPE::Regex documentation, for information on the main class.
π AUTHOR π
The original author is Jeff "japhy" Pinyan (CPAN ID: PINYAN).
Gene Sullivan (gsullivan@cpan.org) is a co-maintainer.
π LICENSE π
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
and that's a wrap on part 2, bestie π this was perl v5.42.0, dated 2025-07-25, and you just finished reading Regex::Element(3) β go forth and parse some regexes, you absolute icon β¨π¦
π¦ where this page comes from
- fedora 43: perl-YAPE-Regex 4.00-41.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms