Regex::Element(3)

πŸ“¦
version 4.00 Β· 2 versions
, in fedora 43

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 is undef for 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 a YAPE::Regex::anchor object. 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 a YAPE::Regex::macro object. 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 a YAPE::Regex::oct object. 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 a YAPE::Regex::hex object. 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 a YAPE::Regex::utf8hex object. 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 a YAPE::Regex::bref object. 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 a YAPE::Regex::ctrl object. 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 a YAPE::Regex::named object. 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 a YAPE::Regex::Cchar object. 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 a YAPE::Regex::slash object. 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 a YAPE::Regex::any object. 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 a YAPE::Regex::class object. 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 a YAPE::Regex::text object. 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 a YAPE::Regex::alt object.
  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 a YAPE::Regex::comment object. Takes two arguments: the text of the comment, and whether or not the /x regex 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 /x regex 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 a YAPE::Regex::whitespace object. 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 a YAPE::Regex::flags object. 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 a YAPE::Regex::cut object. 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 a YAPE::Regex::lookahead object. 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 string lookahead(pos) or lookahead(neg).

πŸ”™ Methods for YAPE::Regex::lookbehind πŸ”™

This class represents lookbehinds. Objects have these methods:

  • my $look = YAPE::Regex::lookbehind->new($pos,\@nodes); β€” creates a YAPE::Regex::lookbehind object. 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 string lookbehind(pos) or lookbehind(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 a YAPE::Regex::hex object. 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 string conditional(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 a YAPE::Regex::group object. 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 a YAPE::Regex::capture object. 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 a YAPE::Regex::code object. 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 a YAPE::Regex::later object. 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 a YAPE::Regex::close object. 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