# Regex

Namespace Chevere\Regex

The Regex component is in charge of providing tooling for regular expression (opens new window) (regex) patterns.

# Creating Regex

Create a Regex by passing the pattern.

use Chevere\Regex\Regex;

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

# Regex pattern

# As-is (constructor)

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

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

# Without delimiters

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

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

# Without delimiters and anchors

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

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

# Match

The match method provides preg_match (opens new window).

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

# Assert Match

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

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

# Match All

The matchAll method provides preg_match_all (opens new window).

$regex->matchAll();
// [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!');