# Regex

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

# Creating Regex

Create a Regex by passing the pattern.

use Chevere\Regex\Regex;

$regex = new Regex('/^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('Hello World!'); // [Hello World!]

The matchAll method provides preg_match_all (opens new window).

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

# Attributes

# RegexAttribute

The Chevere\Regex\Attribute\RegexAttribute attribute enables to define a matching regex anywhere attributes are supported.