Answers.Body: <p>Craft's replace filter only supports doing multiple strings replacements at once.  If you want to do a regex replacement, it will have to be it's own separate call.</p>
  
  <p>In your case, you'd have to do something like this:</p>
  
  <pre><code>{% set url =  "http://www.google.com/"|replace('http://', '') %}
  {{ url|replace('/\\/$/', '') }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-17T19:47:31.040Z
Answers.LastActivityDate: 2015-05-17T19:47:31.040Z
Answers.UserDisplayName: Brad Bell
Answers.Body: <p>I think you are getting the twig <a href="http://twig.sensiolabs.org/doc/filters/replace.html" rel="noreferrer">replace</a> filter (which does not have the regex capability) instead of the Craft <a href="http://buildwithcraft.com/docs/templating/filters#replace" rel="noreferrer">replace</a> filter (which does).</p>
  
  <p>So this is a bug in Craft, in that their filter is masked by the twig one.</p>
  
  <p>You could use the <a href="http://twig.sensiolabs.org/doc/filters/trim.html" rel="noreferrer">trim</a> filter to remove trailing <code>/</code>s:</p>
  
  <pre><code>website|replace({'http://':''})|trim('/')
  </code></pre>
  
  <p>Or you could use one of Victor's <a href="https://github.com/victor-in/Craft-TwigPCRE/" rel="noreferrer">Twig PCRE Filters</a>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-29T15:20:37.977Z
Answers.Text: Thank you Marion! Completely forgot about the `trim` filter - perfect solution :)
Answers.UserDisplayName: Katrin
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-17T19:49:51.220Z
Answers.Text: Craft's replace filter overrides Twig's, not visa-versa - although we do keep their base behavior in tact in ours.  I've added an answer for the behavior you were seeing.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-29T14:47:01.757Z
Answers.LastActivityDate: 2015-04-29T14:47:01.757Z
Answers.UserDisplayName: Marion Newlevant
Body: <p>I am trying to remove the <code>http://</code> and trailing slash from a string, so my replace filter looks like this:</p>
  
  <p><code>website|replace({ 'http://': '', '/\\/$/': '' })</code></p>
  
  <p>The <code>http://</code> part works, the trailing slash one doesn't. Why not?</p>
  
Tags: <regex><replace>
Title: Regex to remove trailing slash not working
ThreadText: # Regex to remove trailing slash not working
  
  (Asked by: username_0 on 2015-04-29)
  
  I am trying to remove the `http://` and trailing slash from a string, so my replace filter looks like this:
  
  `website|replace({ 'http://': '', '/\\/$/': '' })`
  
  The `http://` part works, the trailing slash one doesn't. Why not?
  
  **Tags:** regex, replace
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2015-04-29. Score: 7 | Accepted answer
  
  I think you are getting the twig [replace](http://twig.sensiolabs.org/doc/filters/replace.html) filter (which does not have the regex capability) instead of the Craft [replace](http://buildwithcraft.com/docs/templating/filters#replace) filter (which does).
  
  So this is a bug in Craft, in that their filter is masked by the twig one.
  
  You could use the [trim](http://twig.sensiolabs.org/doc/filters/trim.html) filter to remove trailing `/`s:
  
  ```
  website|replace({'http://':''})|trim('/')
  
  ```
  
  Or you could use one of Victor's [Twig PCRE Filters](https://github.com/victor-in/Craft-TwigPCRE/).
  
  > **Comments:**
  > **username_0**: Thank you username_2! Completely forgot about the `trim` filter - perfect solution :)  
  > **username_1**: Craft's replace filter overrides Twig's, not visa-versa - although we do keep their base behavior in tact in ours.  I've added an answer for the behavior you were seeing.  
  
  ---
  
  ### Answer by username_1 on 2015-05-17. Score: 2
  
  Craft's replace filter only supports doing multiple strings replacements at once. If you want to do a regex replacement, it will have to be it's own separate call.
  
  In your case, you'd have to do something like this:
  
  ```
  {% set url =  "http://www.google.com/"|replace('http://', '') %}
  {{ url|replace('/\\/$/', '') }}
  
  ```
  
  
  ---
  
  