# Regex

Regex

# Summary

Regex enables to work with a validated regular expression (opens new window).

# Installing

Regex is available through Packagist (opens new window) and the repository source is at chevere/regex (opens new window).

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 (opens new window).

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

# Match All

The matchAll method provides preg_match_all (opens new window).

$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!');