Quote regular expression
Before you engage in this article, please visit Handling user input first, if you're interested in using unsafe data in your patterns :)
Suggested articles:
Building your own patterns can be dangerous and lead to security errors. T-Regx offers a rich variety of
dedicated builders including Pattern::prepare()
, Pattern::inject()
and Pattern::bind()
.
Procedural quoting - be careful
There are two methods Pattern::quote()
and Pattern::unquote()
.
First of which works as preg_quote()
is supposed to work (except for the fact that preg_quote()
is broken
before PHP 7.1.3).
- T-Regx
...second of which is the direct opposite:
- T-Regx
Please, keep in mind that this is not a safe way to create patterns with unsafe characters - for that, consider using Prepared Patterns.
Contract
These two methods should be transitive, so:
The contract is that $input
should be identical to $output
for any string
value.