xp-lang/php-pattern-operator

v0.2.0 2024-03-24 13:08 UTC

This package is auto-updated.

Last update: 2024-04-24 13:18:33 UTC


README

Build status on GitHub XP Framework Module BSD Licence Requires PHP 7.4+ Supports PHP 8.0+ Latest Stable Version

Plugin for the XP Compiler which adds an ~ infix operator to the PHP language.

Examples

The pattern operator treats the following expression as a regular expression and returns the matches it generates:

if ($greeting ~ '/^H[ea]llo/') {
  // Matches!
}

if ($matches= $greeting ~ '/^H[ea]llo/') {
  // Work with $matches
}

The pattern is passed to preg_match, so the above is equivalent of writing the following:

if (preg_match($greeting, '/^H[ea]llo/')) {
  // Matches!
}

if (preg_match($greeting, '/^H[ea]llo/', $matches)) {
  // Work with $matches
}

Installation

After installing the XP Compiler into your project, also include this plugin.

$ composer require xp-framework/compiler
# ...

$ composer require xp-lang/php-pattern-operator
# ...

No further action is required.

See also