Regex enables to work with a validated regular expression.
Regex is available through Packagist and the repository source is at chevere/regex.
composer require chevere/regexCreate a Regex by passing the regular expression pattern.
use Chevere\Regex\Regex;
$regex = new Regex('/^Hello World!$/');The __toString method is used to access the pattern passed on instance creation.
$string = $regex->__toString();
// /^Hello World!$/The noDelimiters method is used to access to the regex pattern without delimiters.
$string = $regex->noDelimiters();
// ^Hello World!$The noDelimitersNoAnchors method is used to access to the regex pattern without delimiters and anchors.
$string = $regex->noDelimitersNoAnchors();
// Hello World!The match method provides preg_match.
$array = $regex->match('Hello World!');
// [Hello World!]The matchAll method provides preg_match_all.
$regex->matchAll();
// [Hello World!]The assertMatch method asserts that the string matches. It throws Exceptions\NoMatchException when failing to assert.
$regex->assertMatch('Hello World!');The assertMatchAll method asserts that the string matches all. It throws Exceptions\NoMatchException when failing to assert.
$regex->assertMatchAll('Hello World!');Documentation is available at chevere.org.
Copyright 2024 Rodolfo Berrios A.
Chevere is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.