Answers.Body: <p>Actually, excluding certain tags from being removed is built into the <code>striptags</code> <a href="https://twig.symfony.com/doc/2.x/filters/striptags.html" rel="nofollow noreferrer">filter</a>.</p>
  
  <p>You can use it like this:</p>
  
  <pre><code>{{ articleTextTrim | striptags('&lt;a&gt;') }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-15T15:46:24.730Z
Answers.Text: but then it outputs as html like <a href="www.example.com">link to something</a> I was hope to keep the "link to something" text but remove the html markup.
Answers.UserDisplayName: Danielle Frappier
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-10T21:22:31.390Z
Answers.Text: A raw filer should stop escaping the link. 
  
  {{ articleTextTrim | striptags('<a>') | raw }}
Answers.UserDisplayName: Willhaus
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-14T15:02:34.597Z
Answers.LastActivityDate: 2018-05-14T15:02:34.597Z
Answers.UserDisplayName: Jalen Davenport
Body: <p>I have a rich text (redactor field) that I'm using striptags on to remove the html markup from the front end. However I noticed for links it whips out the link and the text in between. Is this something I can fix with a regular expression? Can you even do that with a twig filter? If so does anyone have an example?</p>
  
  <p>Here is my code: </p>
  
  <pre><code>{% set articleText = myFirstMatrixBlockWithType.blogArticleText %}
  {% if articleText | length &gt; 200 %}
      {% set articleTextTrim = articleText | slice(0, 200) ~ '...' %}
      {{ articleTextTrim | striptags }}
  {% else %}
      {{ articleText | striptags }} 
  {% endif %}
  </code></pre>
  
Tags: <templating><richtext><regex>
Title: striptags but leave link test in between
ThreadText: # striptags but leave link test in between
  
  (Asked by: username_0 on 2018-05-14)
  
  I have a rich text (redactor field) that I'm using striptags on to remove the html markup from the front end. However I noticed for links it whips out the link and the text in between. Is this something I can fix with a regular expression? Can you even do that with a twig filter? If so does anyone have an example?
  
  Here is my code:
  
  ```
  {% set articleText = myFirstMatrixBlockWithType.blogArticleText %}
  {% if articleText | length > 200 %}
      {% set articleTextTrim = articleText | slice(0, 200) ~ '...' %}
      {{ articleTextTrim | striptags }}
  {% else %}
      {{ articleText | striptags }} 
  {% endif %}
  
  ```
  
  **Tags:** templating, richtext, regex
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-05-14. Score: 1
  
  Actually, excluding certain tags from being removed is built into the `striptags` [filter](https://twig.symfony.com/doc/2.x/filters/striptags.html).
  
  You can use it like this:
  
  ```
  {{ articleTextTrim | striptags('<a>') }}
  
  ```
  
  > **Comments:**
  > **username_0**: but then it outputs as html like <a href="www.example.com">link to something</a> I was hope to keep the "link to something" text but remove the html markup.  
  > **username_2**: A raw filer should stop escaping the link.   {{ articleTextTrim | striptags('<a>') | raw }}  
  
  ---
  
  