PCRE2_CODE_COPY(3)

πŸ¦‹ NAME πŸ¦‹

PCRE2 β€” Perl-compatible regular expressions, but make it revised API ✨ (yes bestie, the PCRE2 manual page, this is her πŸ’…)


✨ SYNOPSIS ✨

okay so before anything else, you gotta pull her in:

#include <pcre2.h>

and then the actual star of the show, the function signature, character for character, no cap:

pcre2_code *pcre2_code_copy(const pcre2_code *code);

πŸ’– DESCRIPTION πŸ’–

Okay so pcre2_code_copy() makes a copy of the memory used for a compiled pattern πŸŽ€ β€” and only that memory. It is not copying any memory used by the JIT compiler, bestie. None. Zero. Nada πŸ™ˆ.

Which means: unless you follow it up with a call to pcre2_jit_compile(), your little copy can be used only for non-JIT matching πŸ’€. So don't come crying to me when you try to JIT-match with it. I warned you. Vibe check failed fr fr.

Also, the pointer to the character tables is copied β€” not the tables themselves 🫢 (if you want the actual tables to come along too, go look at pcre2_code_copy_with_tables(), she's the one who does that πŸ’…).

The yield of the function is NULL if code is NULL, or if sufficient memory cannot be obtained 😭. So like, check your pointers and check your malloc energy, y'know?

And if you want the whole entire lore: there's a complete description of the PCRE2 native API in the pcre2api page, and a description of the POSIX API in the pcre2posix page 🌈⭐. Go read them, they ate.


TL;DR bestie: compile β†’ copy β†’ no JIT memory in the copy β†’ pcre2_jit_compile() if you want JIT β†’ check for NULL β†’ character tables are just a pointer, not a photocopy πŸ’œ

πŸŽ€ and that's the page, mwah πŸŽ€ brought to you by PCRE2 10.47, dated 22 November 2016 β€” iconic behavior, honestly πŸ‘‘πŸ’–

πŸ“¦ where this page comes from