chevere/regex

Validated regular expression

1.0.1 2024-01-08 12:27 UTC

This package is auto-updated.

Last update: 2024-11-14 14:51:35 UTC


README

Chevere

Build Code size Apache-2.0 PHPStan Mutation testing badge

Quality Gate Status Maintainability Rating Reliability Rating Security Rating Coverage Technical Debt CodeFactor

Summary

Regex enables to work with a validated regular expression.

Installing

Regex is available through Packagist and the repository source is at chevere/regex.

composer require chevere/regex

Creating Regex

Create a Regex by passing the regular expression pattern.

use Chevere\Regex\Regex;

$regex = new Regex('/^Hello World!$/');

Reading pattern

As-is

The __toString method is used to access the pattern passed on instance creation.

$string = $regex->__toString();
// /^Hello World!$/

Without delimiters

The noDelimiters method is used to access to the regex pattern without delimiters.

$string = $regex->noDelimiters();
// ^Hello World!$

Without delimiters and anchors

The noDelimitersNoAnchors method is used to access to the regex pattern without delimiters and anchors.

$string = $regex->noDelimitersNoAnchors();
// Hello World!

Match

The match method provides preg_match.

$array = $regex->match('Hello World!');
// [Hello World!]

Match All

The matchAll method provides preg_match_all.

$regex->matchAll();
// [Hello World!]

Assert Match

The assertMatch method asserts that the string matches. It throws Exceptions\NoMatchException when failing to assert.

$regex->assertMatch('Hello World!');

Assert Match All

The assertMatchAll method asserts that the string matches all. It throws Exceptions\NoMatchException when failing to assert.

$regex->assertMatchAll('Hello World!');

Documentation

Documentation is available at chevere.org.

License

Copyright 2024 Rodolfo Berrios A.

Chevere is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.