Their example by the link https://learn.getgrav.org/17/themes/twig-tags-filters-functions/functions#regex-replace works.
But something like
{% set result = regex_replace('The quick brown fox', ['/(\s)?/'], ['']) %}
{{ result }}
does not work - the string is not changed
How to use regex in their wrapper?
Update:
Sorry I've overlooked the link in your question.
Try to escape the backslash. See this issue on regex_replace.
The following works fine:
Result: Thequickbrownfox
Btw: The parenthesis and question mark are not necessary in your example.
Original:
Grav adds a custom filter for this. See https://learn.getgrav.org/17/themes/twig-tags-filters-functions/filters#regex-replace.
It's a wrapper around PHP's
preg_replace().Example:
which yields: