# Regex

The Regex component is in charge of providing tooling for typed regex patterns.

RegexInterface describes the interface for the component in charge of defining a Regex.

# Creating Regex

Create a new Regex by passing the pattern.

use Chevere\Components\Regex\Regex;

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

# Accessing pattern

# As-is (constructor)

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

$regex->toString(); // /^Hello World!$/

# Without delimiters

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

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

# Without delimiters and anchors

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

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

# String matching

The match method provides preg_match.

$regex->match(string: 'Hello World!'); // [Hello World!]

The matchAll method provides preg_match_all.

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