- Issue created by @msn5158
- 🇷🇺Russia Chi
Twig requires escaping backward slashes.
{{ '50/01'|preg_replace('/\\//','') }}
If you change regexp delimiters you won't need to escape anything.
{{ '50/01'|preg_replace('#/#','') }}
Also note that
preg_replace
is intended for processing strings through regular expressions. In your case it's better to use simple replace filter from Twig core.{{ '50/01'|replace({'/': ''}) }}
I know replace filter, However, my use case requires matching of some strings:
{{ '50/01'|preg_replace('/^(11|12|31|50)\\/(01|02)$/','$1') }}
Thank you, It works normally.
- Status changed to Fixed
11 months ago 9:05am 21 May 2024 Automatically closed - issue fixed for 2 weeks with no activity.