Option to disable regex in replace
filter
#13642
-
Hi Folks, Following on from an issue I posted yesterday, I have been thinking about whether it is a good idea to have the The impetus for the above issue was actually due to some existing code breaking after updating to Craft 4.5.x The goal of the existing code was to remove a path segment such as
Previously that would set Since updating to Craft 4.5, this instead removes all instances of the While this is technically the expected behaviour since the new version supports a regex, it is a bit of a breaking change in a sense, since the The pattern kindly provided by @wsydney76 in that issue, I've been trying to think about ways of preventing similar unexpected behaviour in future. Perhaps an option on the Thoughts? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Sorry, that was an unintended change in behavior. I’ve just added a new {% set url = 'https://example.com/a/' %}
{% set urlWithoutPath = url|replace({'/a/': ''}, regex=false) %} |
Beta Was this translation helpful? Give feedback.
Sorry, that was an unintended change in behavior.
I’ve just added a new
regex
argument to the|replace
filter for the next release, which you can set tofalse
to explicitly disable regex parsing: