# replaceRE returns generic syntax error

**URL:** <https://discourse.gohugo.io/t/replacere-returns-generic-syntax-error/7491>\
**Category:** support\
**Created:** [July 18, 2017, 9:47am UTC](https://discourse.gohugo.io/t/replacere-returns-generic-syntax-error/7491 "2017-07-18T09:47:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Heydon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/heydon/32/3010_2.png) [@Heydon](https://discourse.gohugo.io/u/Heydon)\
**Post date:** [July 18, 2017, 9:47am UTC](https://discourse.gohugo.io/t/replacere-returns-generic-syntax-error/7491/1 "2017-07-18T09:47:42Z")

</div>

I’m a regex noob, so this may be a silly question, but why does the following not work?

```auto
{{ $highlighted := replaceRE "\?\?(.*?)\?\?" "<mark>$1</mark>" "??thing to highlight??" }}

```

The regex appears to be valid when testing it in [http://regexr.com/](http://regexr.com/), but I just get a generic syntax error in my console. If I break the regex, a regex-specific error comes out — for example, if I unescape the “?” marks. I tried it without the markup around the capture group in the second argument too, but no luck.

Thanks!

---

<div class="post-metadata">

**Author:** ![budparr](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/budparr/32/749_2.png) [@budparr](https://discourse.gohugo.io/u/budparr)\
**Post date:** [July 18, 2017, 12:40pm UTC](https://discourse.gohugo.io/t/replacere-returns-generic-syntax-error/7491/2 "2017-07-18T12:40:44Z")

</div>

Try using [https://regex101.com/](https://regex101.com/) with “golang” selected.

---

<div class="post-metadata">

**Author:** ![Heydon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/heydon/32/3010_2.png) [@Heydon](https://discourse.gohugo.io/u/Heydon)\
**Post date:** [July 18, 2017, 12:47pm UTC](https://discourse.gohugo.io/t/replacere-returns-generic-syntax-error/7491/3 "2017-07-18T12:47:12Z")

</div>

Thanks but I don’t see the difference. `\?\?(.*?)\?\?` works with golang selected. Is there anything I have to wrap the expression in?

---

<div class="post-metadata">

**Author:** ![budparr](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/budparr/32/749_2.png) [@budparr](https://discourse.gohugo.io/u/budparr)\
**Post date:** [July 19, 2017, 3:25pm UTC](https://discourse.gohugo.io/t/replacere-returns-generic-syntax-error/7491/4 "2017-07-19T15:25:41Z")

</div>

Hi @Heydon - I checked this out and it’s not working for me either. I’m not sure, but I think maybe your right about a missing flag or something (just looking around the forums), but TBH I don’t know. My first post was just to make sure you were checking your syntax with the same type of parser that Hugo uses.

---

<div class="post-metadata">

**Author:** ![Heydon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/heydon/32/3010_2.png) [@Heydon](https://discourse.gohugo.io/u/Heydon)\
**Post date:** [July 19, 2017, 3:27pm UTC](https://discourse.gohugo.io/t/replacere-returns-generic-syntax-error/7491/5 "2017-07-19T15:27:12Z")

</div>

Thanks for getting back to me @budparr.

It doesn’t seem to be a regression because the example from the docs appears to work, so I’m not sure what’s going on.

---

<div class="post-metadata">

**Author:** ![moorereason](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/moorereason/32/592_2.png) [@moorereason](https://discourse.gohugo.io/u/moorereason)\
**Post date:** [July 19, 2017, 5:05pm UTC](https://discourse.gohugo.io/t/replacere-returns-generic-syntax-error/7491/6 "2017-07-19T17:05:20Z")

</div>

You need to escape your backslashes in the pattern string.

---

<div class="post-metadata">

**Author:** ![Heydon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/heydon/32/3010_2.png) [@Heydon](https://discourse.gohugo.io/u/Heydon)\
**Post date:** [July 19, 2017, 8:40pm UTC](https://discourse.gohugo.io/t/replacere-returns-generic-syntax-error/7491/7 "2017-07-19T20:40:48Z")

</div>

I need to escape the backslashes that are used to escape the “?” characters?

---

<div class="post-metadata">

**Author:** ![moorereason](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/moorereason/32/592_2.png) [@moorereason](https://discourse.gohugo.io/u/moorereason)\
**Post date:** [July 20, 2017, 2:20pm UTC](https://discourse.gohugo.io/t/replacere-returns-generic-syntax-error/7491/8 "2017-07-20T14:20:33Z")

</div>

Yes, that’s what I mean.

```auto
"\\?\\?(.*?)\\?\\?"

```

You can also use backticks to send a literal string, which doesn’t support escape sequences.

```auto
`\?\?(.*?)\?\?`

```
