Answers.Body: <p>You'll need to double escape those backslashes in the regex.</p>
  
  <pre><code>  {% set ig = user.instagram|raw|replace('/(?:(?:http|https):\\/\\/)?(?:www.)?(?:instagram.com|instagr.am)\\/([A-Za-z0-9-_\\.]+)/im') %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-16T22:27:14.000Z
Answers.LastActivityDate: 2019-05-16T22:27:14.000Z
Answers.UserDisplayName: Brad Bell
Body: <p>I've tested the regex and seems to work perfectly, but when placing it within Craft it seems to throw the following error:</p>
  
  <blockquote>
    <p>preg_replace(): Unknown modifier '/'</p>
  </blockquote>
  
  <pre><code>  {% set ig = user.instagram|raw|replace('/(?:(?:http|https):\/\/)?(?:www.)?(?:instagram.com|instagr.am)\/([A-Za-z0-9-_\.]+)/im') %}
    {{ ig }}
  </code></pre>
  
Tags: <templating><regex>
Title: Replace throwing Unknown Modifier Error
ThreadText: # Replace throwing Unknown Modifier Error
  
  (Asked by: username_0 on 2019-05-16)
  
  I've tested the regex and seems to work perfectly, but when placing it within Craft it seems to throw the following error:
  
  > preg\_replace(): Unknown modifier '/'
  
  ```
    {% set ig = user.instagram|raw|replace('/(?:(?:http|https):\/\/)?(?:www.)?(?:instagram.com|instagr.am)\/([A-Za-z0-9-_\.]+)/im') %}
    {{ ig }}
  
  ```
  
  **Tags:** templating, regex
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-05-16. Score: 1 | Accepted answer
  
  You'll need to double escape those backslashes in the regex.
  
  ```
    {% set ig = user.instagram|raw|replace('/(?:(?:http|https):\\/\\/)?(?:www.)?(?:instagram.com|instagr.am)\\/([A-Za-z0-9-_\\.]+)/im') %}
  
  ```
  
  
  ---
  
  