PHPackages                             sl5net/preg-contentfinder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. sl5net/preg-contentfinder

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sl5net/preg-contentfinder
=========================

A class to find content based on regular expressions.

v1.2.0(10mo ago)501GPL-3.0-or-laterPHPPHP ^8.2 || ^8.3

Since May 6Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/sl5net/SL5_preg_contentFinder)[ Packagist](https://packagist.org/packages/sl5net/preg-contentfinder)[ RSS](/packages/sl5net-preg-contentfinder/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (8)Used By (0)

PregContentFinder
=================

[](#pregcontentfinder)

**A powerful and robust PHP library for finding, extracting, and transforming content within text based on regular expression (PCRE) delimiters, featuring advanced support for nested structures, custom callback processing, and intelligent delimiter handling.**

[![Latest Stable Version](https://camo.githubusercontent.com/b9decaa056a43f808daf4191e852393ce73f5a6cd553d4269f49e2da340845e9/68747470733a2f2f706f7365722e707567782e6f72672f736c356e65742f707265672d636f6e74656e7466696e6465722f762f737461626c65)](https://packagist.org/packages/sl5net/preg-contentfinder)[![Total Downloads](https://camo.githubusercontent.com/fd8888bdbde2fc40b582b569e775f979e9edde33aeb805ff4aa4d6ac694472ad/68747470733a2f2f706f7365722e707567782e6f72672f736c356e65742f707265672d636f6e74656e7466696e6465722f646f776e6c6f616473)](https://packagist.org/packages/sl5net/preg-contentfinder)[![License](https://camo.githubusercontent.com/437cff53c45f19ad24b2170f3451bf5dfe8bce7a7e3a68ae622fda93fdcb47b4/68747470733a2f2f706f7365722e707567782e6f72672f736c356e65742f707265672d636f6e74656e7466696e6465722f6c6963656e7365)](https://packagist.org/packages/sl5net/preg-contentfinder)

**A Legacy of Stability:** The fundamental recursive parsing logic and the intelligent handling of delimiter conflicts have been stable and functional **since its early years (around 2002-2003, likely PHP 4)**. Subsequent updates primarily focused on adapting to new PHP versions (like PHP 5.6). This latest modernization brings the proven core engine to **PHP 8.1+**, integrating it with Composer and modern PHP standards.

It excels where simple string functions or basic regex fall short, particularly with nested structures and context-dependent transformations.

Key Features
------------

[](#key-features)

- **Delimiter-Based Searching:** Use strings or full PCRE regular expressions for start and end delimiters.
- **Intelligent Nested Structure Handling:** Reliably finds content within correctly balanced and nested delimiter pairs, even when the content itself contains delimiter characters. **You often don't need to worry about manually escaping delimiter characters within your content.**
- **Recursive Processing:** Apply transformations recursively through nested structures using `getContent_user_func_recursive`.
- **Custom Callback Functions:** Pass PHP callables to dynamically process and transform the content found between delimiters, receiving context like nesting depth and match details.
- **Flexible Search Modes:**
    - `lazyWhiteSpace`: Treats delimiters as literal strings, quoting them and making whitespace flexible.
    - `dontTouchThis`: Treats delimiters as raw PCRE patterns provided by the user.
    - `use_BackReference_IfExists_()$1${1}`: Allows the end delimiter's regex to use backreferences from the start delimiter's match (e.g., for matching `...`).
- **Content Access:** Easily retrieve content *between*, *before*, or *after* matched delimiters for the current match.
- **Modernized:** PHP 8.1+ compatible, PSR-4 compliant, available via Composer.
- **Well-Tested:** Backed by ~100 unit tests ensuring core functionality and robustness.

Why PregContentFinder?
----------------------

[](#why-pregcontentfinder)

Use this library when you need to:

- Parse and transform custom template languages or markup (like BBCode).
- Reliably extract data from semi-structured text files with potentially nested blocks, even if those blocks contain delimiter characters.
- Perform context-aware text transformations using callbacks based on nesting or content.
- Analyze or refactor code structures based on block delimiters.
- Implement interpreters for simple, domain-specific languages.

Its unique combination of features, especially the robust handling of nested structures and internal management of delimiter conflicts, makes it a powerful tool for complex text processing tasks.

Installation
------------

[](#installation)

The recommended way to install PregContentFinder is via [Composer](https://getcomposer.org/):

```
composer require sl5net/preg-contentfinder
```

Basic Usage

```
