chevere / regex
Validated regular expression
Installs: 4 182
Dependents: 4
Suggesters: 0
Security: 0
Stars: 4
Watchers: 0
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- chevere/message: ^1.0.0
Requires (Dev)
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9.5
- symplify/easy-coding-standard: ^11.1
README
Summary
Regex enables to work with a validated regular expression.
Installing
Regex is available through Packagist and the repository source is at chevere/regex.
composer require chevere/regex
Creating Regex
Create a Regex by passing the regular expression pattern.
use Chevere\Regex\Regex; $regex = new Regex('/^Hello World!$/');
Reading pattern
As-is
The __toString
method is used to access the pattern passed on instance creation.
$string = $regex->__toString(); // /^Hello World!$/
Without delimiters
The noDelimiters
method is used to access to the regex pattern without delimiters.
$string = $regex->noDelimiters(); // ^Hello World!$
Without delimiters and anchors
The noDelimitersNoAnchors
method is used to access to the regex pattern without delimiters and anchors.
$string = $regex->noDelimitersNoAnchors(); // Hello World!
Match
The match
method provides preg_match.
$array = $regex->match('Hello World!'); // [Hello World!]
Match All
The matchAll
method provides preg_match_all.
$regex->matchAll(); // [Hello World!]
Assert Match
The assertMatch
method asserts that the string matches. It throws Exceptions\NoMatchException
when failing to assert.
$regex->assertMatch('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!');
Documentation
Documentation is available at chevere.org.
License
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.