JE::Ob...RegExp(3pm)
π JE::Object::RegExp β the JavaScript regex glow-up π
okay so bestie, this is the page for JE::Object::RegExp, a perl module straight out of the User Contributed Perl Documentation era, and it's literally the JavaScript regular expression (RegExp object) class. yes. we're doing JS regexes in Perl. it's giving multilingual icon behavior β¨
πΈ SYNOPSIS πΈ
here's the vibe, copy-paste ready, no notes:
use JE;
use JE::Object::RegExp;
$j = new JE;
$js_regexp = new JE::Object::RegExp $j, "(.*)", 'ims';
$perl_qr = $js_regexp->value;
$some_string =~ $js_regexp; # You can use it as a qr//
like, look at that last line. you can just use it as a qr//. main character energy fr fr π
β¨ DESCRIPTION β¨
so this class implements JavaScript regular expressions for JE. that's the whole gig π
for the description of most of the interface, go read JE::Types β only the stuff that's specific to JE::Object::RegExp gets explained right here.
a RegExp object will stringify the exact same way as a qr//, which is why you can use =~ on it. and ngl that is different from the return value of the to_string method (which is the way it stringifies in JS). two different stringifications, two different contexts, don't mix them up bestie π
since JE's regular expressions use Perl's engine underneath, all the features Perl provides that are not part of the ECMAScript spec are supported β except for these two problem children:
(?s)and(?m)β they literally don't do anything π(?|...)β unpredictable. no cap. π
and a little lore drop for the historians: in versions prior to 0.042, a hyphen adjacent to \d, \s or \w in a character class was unpredictable (sometimes a syntax error π). now it's interpreted literally. this matches what most implementations do, which happens to be the same as Perl's behaviour. (it is a syntax error in ECMAScript, just so we're clear. the spec said no but the streets said yes π)
π¦ METHODS π¦
value
returns a Perl qr// regular expression. slay.
β οΈ okay heads up, this one's a real caveat: if the regular expression, or the string that's being matched against it, contains characters outside the Basic Multilingual Plane (whose character codes exceed0xffff), the behavior is undefined β for now at least. I still need to solve the problem caused by JS's unintuitive use of raw surrogates. (In JS,/../will match a surrogate pair, which is considered to be one character in Perl. This means that the same regexp matched against the same string will produce different results in Perl and JS.)
like, that's not me being dramatic, that's the actual state of things. undefined behavior, no cap. π
class
returns the string 'RegExp'. short, sweet, iconic, periodt β¨
π SEE ALSO π
go read these too, they're the friend group:
JEJE::TypesJE::Object
and that's the page!! brought to you by perl v5.36.0, dated 2023-08-25, from the User Contributed Perl Documentation collection π stay regexing, bestie, and remember: =~ is your best friend and (?|...) is your chaos gremlin π§πΈ
π¦ where this page comes from
- debian trixie: libje-perl 0.066-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libje-perl 0.066-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libje-perl 0.066-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libje-perl 0.066-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms