BSON::Regex(3pm)

πŸ“¦
version 1.12.2 Β· 5 versions
, in debian bookworm, ubuntu jammy, ubuntu noble

πŸ’– 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 the re 'eval' pragma is in force. like, genuinely, this is the scary part. you are strongly advised to read re and to never use untrusted input with try_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. πŸ’œ


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