<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>

CC BY-SA 4.0
2019-05-16T22:27:14.000Z
2019-05-16T22:27:14.000Z
Brad Bell
<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>

<templating><regex>
Replace throwing Unknown Modifier Error
# 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') %}


---

