BSON::Regex(3pm)
π BSON::Regex π
okay bestie, so this is the Perl manual page for BSON::Regex β it's a BSON type wrapper for regular expressions, and honestly? she's cute, she's small, she's doing her job. version v1.12.2, no cap. let's get into it π«Ά
β¨ SYNOPSIS β¨
use BSON::Types ':all';
$regex = bson_regex( $pattern );
$regex = bson_regex( $pattern, $flags );
that's it. that's the whole vibe. two lines and you're iconic π
πΈ DESCRIPTION πΈ
so like, this module gives you a BSON type wrapper for a PCRE regular expression plus some optional flags. it wraps the pattern and the flags up together all nice so BSON can carry them around. periodt β¨
π ATTRIBUTES π
pattern
a string holding a PCRE regular expression pattern β and listen, it is not a qr object, and there are no slashes in there, okay? just the raw pattern. default is the empty string, because sometimes you're mysterious like that π
flags
a string of regular expression flags. here's the tea: when the object gets constructed, the flags get sorted and duplicates get removed β she's organized, she's tidy, she's that girl π
the supported flags are imxlsu. anything invalid? boom, exception. she does not play. default is the empty string.
π¦ METHODS π¦
try_compile
my $qr = $regexp->try_compile;
she tries to compile the pattern and flags into a reference to a regular expression. and if the pattern or the flags can't be compiled? an exception gets thrown. no soft launch, no "we'll see", just an exception π
β οΈ SECURITY NOTE: running a regular expression can evaluate arbitrary code if there 'eval'pragma is in force. like, genuinely, this is the scary part. you are strongly advised to readreand to never use untrusted input withtry_compile. bestie please. i am begging. π do not feed her sketchy input, she will not survive it and neither will you π
TO_JSON
if the BSON_EXTJSON option is true, you get back a hashref that's compatible with MongoDB's extended JSON format β that's the spec over at https://github.com/mongodb/specifications/blob/master/source/extended-json.rst β and it represents the thing as a document, like so:
{"$regularExpression" : { pattern: "<pattern>", "options" : "<flags>"} }
look at her. she ate. π₯
but if BSON_EXTJSON is false? an error is thrown, because honestly this value just can't be represented in JSON any other way. it's giving "sorry babe, not possible" π
π AUTHORS π
- David Golden
<david@mongodb.com> - Stefan G.
<minimalist@lavabit.com>
two icons. we love them. π
π COPYRIGHT AND LICENSE π
This software is Copyright (c) 2020 by Stefan G. and MongoDB, Inc.
This is free software, licensed under:
The Apache License, Version 2.0, January 2004
and that's the whole page, bestie! πβ¨ this manual page came to you courtesy of perl v5.30.3 on 2020-08-14, and it's the BSON::Regex(3pm) page β so go forth, compile responsibly, and never trust the input π¦π
π¦ where this page comes from
- debian bookworm: libbson-perl 1.12.2-1 Β· Apache-2.0
- ubuntu jammy: libbson-perl 1.12.2-1 Β· Apache-2.0
- ubuntu noble: libbson-perl 1.12.2-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms