Answers.Body: <p>Something like this should work:</p>
  
  <pre><code>{{ snippet|replace('/&lt;img([\w\W]+?)&gt;/', '') }}
  </code></pre>
  
  <p>You can see an explanation of the regex in the right column of <a href="https://regex101.com/r/DvJHeY/1" rel="nofollow noreferrer">https://regex101.com/r/DvJHeY/1</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-21T18:59:58.303Z
Answers.Text: Awesome, thanks again Brad!
Answers.UserDisplayName: jtenclay
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-20T20:12:49.220Z
Answers.LastActivityDate: 2017-09-20T20:12:49.220Z
Answers.UserDisplayName: Brad Bell
Body: <p>I'm looking to format out image tags from a string using the <code>|replace</code> filter. The behavior I'm looking for is to give it a string like this:</p>
  
  <p><code>&lt;img src="test.jpg"&gt;&lt;p&gt;some text&lt;/p&gt;&lt;img src="test.jpg"&gt;</code></p>
  
  <p>and get back:</p>
  
  <p><code>&lt;p&gt;some text&lt;/p&gt;</code></p>
  
  <p>Unfortunately, when I use <code>{{ snippet|replace('/&lt;img(.*)&gt;/', '') }}</code> it matches the entire string, from the opening <code>&lt;img</code> to the second image's closing <code>&gt;</code> rather than matching both <code>&lt;img&gt;</code> tags individually. How can I force the regex to match only through the first <code>&gt;</code> it finds before continuing?</p>
  
Tags: <filter><regex>
Title: |replace filter is matching too many characters
ThreadText: # |replace filter is matching too many characters
  
  (Asked by: username_0 on 2017-09-20)
  
  I'm looking to format out image tags from a string using the `|replace` filter. The behavior I'm looking for is to give it a string like this:
  
  `<img src="test.jpg"><p>some text</p><img src="test.jpg">`
  
  and get back:
  
  `<p>some text</p>`
  
  Unfortunately, when I use `{{ snippet|replace('/<img(.*)>/', '') }}` it matches the entire string, from the opening `<img` to the second image's closing `>` rather than matching both `<img>` tags individually. How can I force the regex to match only through the first `>` it finds before continuing?
  
  **Tags:** filter, regex
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-09-20. Score: 1 | Accepted answer
  
  Something like this should work:
  
  ```
  {{ snippet|replace('/<img([\w\W]+?)>/', '') }}
  
  ```
  
  You can see an explanation of the regex in the right column of <https://regex101.com/r/DvJHeY/1>
  
  > **Comments:**
  > **username_0**: Awesome, thanks again username_1!  
  
  ---
  
  