BSON_APPEND_REGEX(3)

πŸ’… BSON_APPEND_REGEX πŸ’…

okay bestie, this one's from the libbson girlies β€” it's the BSON_APPEND_REGEX(3) page and honestly it's giving "small function, big slay" ✨


✨ SYNOPSIS ✨

so there's a macro and a function, because of course there is πŸ’…

#define BSON_APPEND_REGEX(b, key, val, opt) \
   bson_append_regex (b, key, (int) strlen (key), val, opt)

bool
bson_append_regex (bson_t *bson,
                   const char *key,
                   int key_length,
                   const char *regex,
                   const char *options);

like, the macro is just the function but it does the strlen() for you so you don't have to. main character energy honestly πŸŽ€


🌸 PARAMETERS 🌸

  • bson β€” a bson_t. that's the whole vibe. the document you're adding to πŸ’–
  • key β€” an ASCII C string with the name of the field. yep. just the name. ngl ASCII only, keep it cute πŸ¦‹
  • key_length β€” the length of key in bytes, or -1 if you want it to figure that out with strlen(). lowkey the lazy-girl option and we respect it πŸ™ˆ
  • regex β€” an ASCII string containing the regex. the actual pattern, bestie πŸ”₯
  • options β€” an optional string containing the regex options as a string. optional!! so you can absolutely skip it πŸ’œ

πŸ¦‹ DESCRIPTION πŸ¦‹

so what it does: it appends a brand new field onto bson, and the type is BSON_TYPE_REGEX β€” iconic, we love a dedicated regex type πŸ’…

regex should be the regex string. options should contain the options for the regex. simple, clean, no cap ✨

and the valid characters for options? bestie I got you, here's the whole list πŸŽ€

  • 'i' β€” for case-insensitive. so ABC and abc are the same thing, slay πŸ’–
  • 'm' β€” for multiple matching πŸ‘‘
  • 'x' β€” for verbose mode 🌸
  • 'l' β€” to make w and W locale dependent. yep, the lowercase and uppercase ones, exactly those 🌈
  • 's' β€” for dotall mode, which means '.' matches everything. every single thing. periodt ⭐
  • 'u' β€” to make w and W match unicode πŸ¦‹
fr fr, those are the exact characters β€” don't go inventing new ones, bestie 😭

⭐ RETURNS ⭐

Returns true if the operation was applied successfully. if it worked, it worked πŸ’–

but heads up: the function will fail if appending the regex grows bson larger than INT32_MAX. like, that's the ceiling. if you blow past it, it's not happening, sorry not sorry πŸ’€


πŸ‘‘ AUTHOR πŸ‘‘

MongoDB, Inc β€” the literal authors, we stan 🫢


2009-present, MongoDB, Inc. β€” all rights reserved, all vibes preserved 🌸


and that's the whole page, bestie!! this was libbson 2.5.6, dated Oct 09, 2026 β€” go forth and append those regexes, you absolute icon πŸ’…βœ¨πŸ“

πŸ“¦ where this page comes from