Validate a pattern

This chapter doesn't contain PHP code snippets, because PHP PCRE doesn't provide a way to validate patterns.

You can check whether a pattern is valid with pattern()->valid() method.

pattern('I am a valid pattern')->valid();

Remember, pattern()->valid() doesn't throw any exception nor issues any warnings. It only returns true/false.

pattern('I am an (( invalid }} pattern')->valid();

Old-school patterns

Undelimited patterns can be validated with pattern()/Pattern::of(). To validate old-school patterns (e.g. /Hello/i), use Pattern::pcre():

Pattern::pcre('/I am an valid pattern/m')->valid();
Last updated on