Need help with T-Regx?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

265 Stars 11 Forks MIT License 1.1K Commits 5 Opened issues

Description

Library for PHP regular expression, providing high-level API.

Services available

!
?

Need anything else?

Contributors list

T-Regx

Build status

T-Regx | Regular Expressions library

PHP regular expressions brought up to modern standards.

See documentation at t-regx.com.

last commit commit activity Unit tests Repository size FQN PRs Welcome

PHP Version PHP Version PHP Version PHP Version PHP Version

  1. Installation
  2. API
  3. Documentation
  4. T-Regx fiddle - Try online
  5. Overview
  6. Comparison
  7. License

Installation

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

composer require rawr/t-regx

Current development priorities, regarding release of 1.0:

  • Handle corner-cases with prepared patterns #91 [in progress]
  • Separate SafeRegex and CleanRegex into to two packages, so users can choose what they want #103
  • Add documentation to each T-Regx public method #17 [in progress]
  • Release 1.0
  • Revamp of t-regx.com documentation [in progress]

API

You, choose the interface: - I choose to keep PHP methods (but protected from errors):

Scroll to see -

preg::match_all()
,
preg::replace_callback()
,
preg::split()
- I choose the modern regex API:

Scroll to see -

pattern()->test()
,
pattern()->match()
,
pattern()->replace()

Documentation

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

Try it online, in your browser!

Open T-Regx fiddle and start playing around.

Why T-Regx stands out?

:bulb: See documentation at t-regx.com

  • No change in API!

    • You can use T-Regx safe features and exception-based error handling, without changing your API.

    Simply swap

    preg_match()
    to
    preg::match()
    , and your method is safe! Arguments and return types remain the same.
  • Prepared patterns

Using user data (for example with

preg_quote()
) isn't always safe with PCRE, as well as just not being that convenient to use. T-Regx provides
Pattern::inject()
and
Pattern::bind()
methods, designed specifically for handling potentially unsafe data.
Pattern::format()
allows converting user-supplied masks into full-fledged patterns safely.
  • Working with the developer

  • Automatic delimiters for your pattern

    Surrounding slashes or tildes (

    /pattern/
    or
    ~patttern~
    ) are not compulsory.
  • Converting Warnings/Errors to Exceptions

    • Malformed patterns in
      preg_()
      methods don't make
      preg_last_error()
      to return error.
    • Notices, warnings or errors during
      preg::
      are converted to exceptions.
    • preg_()
      can never fail, because it throws
      PregException
      on warning/error.
    • In some cases,
      preg_()
      methods might fail, return
      false
      /
      null
      and NOT trigger a warning. Separate exception,
      SuspectedReturnPregException
      is then thrown by T-Regx.
  • Written with clean API

    • Descriptive, chainable interface
    • SRP methods
    • UTF-8 support out-of-the-box
    • No Reflection used
      ,
      No (...varargs)
      ,
      No (boolean arguments, true)
      ,
      (No flags, 1)
      ,
      [No [nested, [arrays]]]
  • Protects your from fatal errors

    Certain arguments cause fatal errors with

    preg_()
    methods. T-Regx will throw a catchable exception, instead of a Fatal Error.

What's better

Ugly api

or

Pretty api

Sponsors

Andreas Leathley - developing SquirrelPHP

T-Regx is developed thanks to

JetBrains

License

T-Regx is MIT licensed.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.