Send Feedback
Skip to content

The PCRE2 Module in KDB-X

This page provides an overview of the PCRE2 module in KDB-X.

The PCRE2 module for KDB-X integrates the Perl Compatible Regular Expressions (PCRE2) library, enabling powerful text matching and replacement using Perl-style regular expressions directly in q code.

This module allows you to write concise, expressive text-processing logic that goes beyond q’s native pattern capabilities - ideal for parsing, transforming, or validating textual data streams within KDB-X environments.

Key features

  • Perl-compatible regular expressions - use advanced regex syntax including lookahead, lookbehind, backreferences, named groups, and more.

  • High-performance matching and replacing - powered by the PCRE2 C library for optimal speed.

  • Flexible options - control case sensitivity, multiline matching, and other behaviors using simple q arguments.

  • Simple q integration - accessible through intuitive function calls: pcre2.match and pcre2.replace.

  • Cross-platform compatibility - works on Linux and macOS with native PCRE2 support.

Use cases

Use the PCRE2 module for:

  • Log parsing to extract structured fields from unstructured text.

  • Data cleaning to replace or reformat patterns in text datasets.

  • Validation to enforce string patterns (for example, emails, dates, identifiers).

  • Search utilities to implement custom text search and filtering pipelines within q scripts.

Next steps

  • See the PCRE2 documentation on GitHub for more information on API references and how to install and use the module.