regex_quote
The regex_quote filter puts a backslash in front of every character that is part of the regular expression syntax.
The special regular expression characters are: . \ + * ? [ ^ ] $ ( ) { } = ! < > | : -.
{% set regex = value|regex_quote() %}
If you are using a delimiter other than / in your regular expression then you can pass that to regex_quote to escape that character as well.
{% set regex = value|regex_quote('#') %}
Arguments
The regex_quote filter has the following signature.
regex_quote(delimiter)
delimiter is optional.
Argument | Description |
---|---|
delimiter | Optional argument. If used then the passed character will also be escaped with a backslash. {% set regex = value|regex_quote('#') %} |