# PCRE2 Module

*This page explains what the PCRE2 module is and when to use it.*

The PCRE2 module in KDB-X integrates the <a href="https://github.com/PCRE2Project/pcre2" target="_blank" rel="noopener noreferrer">Perl Compatible Regular Expressions (PCRE2) library</a>, 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](https://github.com/KxSystems/fusionx/tree/main/pcre2/docs){target=_blank} on GitHub for more information on API references and how to install and use the module.
