A set of helper functions with modern interface for built-in PHP preg_
functions. Revamped approach, all the goodies
extracted from T-Regx library, waste removed.
Testing string subject against regex pattern:
re_test('[a-z]+', 'word');
// bool (true)
re_test('[a-z]+', 'WORD', modifiers:'i');
// bool (true)
Helpful error message for syntax errors in regex patterns:
try {
re_test('[a-z', 'word');
} catch (\Regex\MalformedRegex $exception) {
// 'missing terminating ] for character class'
}
Exceptions with positions of syntax errors in the pattern:
re_test('(Foo:[a-z]))\w+', 'word');
Regex\MalformedRegex: unmatched closing parenthesis
(Foo:[a-z]))\w+
^
Literal values in patterns:
re_test('^foo' . \preg_quote('$12') . '$', 'foo:$12'); // won't work
re_test(re_quote('^foo@$', ['$12']), 'foo:$12'); // inject literal values into @ placeholders