# Regex

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

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

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

The matchAll method provides preg_match_all (opens new window).

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