t-regx / T-Regx

Simple library for regular expressions in PHP.
https://t-regx.com
MIT License
448 stars 16 forks source link
pcre php prepared-patterns regex regexp regular-expressions

T-Regx

Build status Unit tests latest: 0.41.5 dependencies: 0

T-Regx | Regular Expressions library

PHP regular expressions brought up to modern standards.

See documentation at t-regx.com.

last commit commit activity Commits since Unit tests Unit tests Code Climate FQN PRs Welcome Gitter

OS Arch OS Arch OS Arch OS Arch

PHP Version PHP Version PHP Version PHP Version PHP Version PHP Version PHP Version

  1. Installation
  2. Examples
  3. Documentation
  4. T-Regx fiddle - Try online
  5. API
    1. For standard projects -pattern()
    2. For legacy projects - preg::match_all()
  6. Overview
    1. Prepared patterns
    2. Working with the developer
    3. Clean API
    4. Fatal errors
    5. Clean Code
    6. Exceptions vs. errors
  7. Comparison
    1. Exceptions over warnings/errors
    2. Working with the developer
    3. Written with clean API in mind
    4. Philosophy of Uncle Bob and "Clean Code"
  8. Plans for the future
  9. Sponsors
  10. License

Buy me a coffee!

Installation

Installation for PHP 7.1 and later (PHP 8 as well):

composer require rawr/t-regx

T-Regx only requires mb-string extension. No additional dependencies or extensions are required.

Examples

Illustration of methods match(), test() and count().

$pattern = Pattern::of("ups"); // pattern("ups") also works
$matcher = $pattern->match('yay, ups');

foreach ($matcher as $detail) {
    $detail->text();    // (string) "ups";
    $detail->offset();  // (int) 0
}

if (!$matcher->test()) {
    echo "No occurrances found";
} else {
    echo "Found {$matcher->count()} occurrences";
}

Documentation

Full API documentation is available at t-regx.com. List of changes is available in ChangeLog.md.

Quick links:

Try it online, in your browser!

Open T-Regx fiddle and start playing around right in your browser. Try now!

API

Choose the interface:

For standard projects, we suggest pattern(). For legacy projects, we suggest preg::match_all().

Why T-Regx stands out?

:bulb: See documentation at t-regx.com

Comparison

Ugly api

or

Pretty api

Current work in progress

Current development priorities, regarding release of 1.0:

Sponsors

T-Regx is developed thanks to

JetBrains

License

T-Regx is MIT licensed.