# Bug of replace?

**URL:** <https://discourse.julialang.org/t/bug-of-replace/3023>\
**Category:** General Usage\
**Tags:** question\
**Created:** [April 3, 2017, 3:05pm UTC](https://discourse.julialang.org/t/bug-of-replace/3023 "2017-04-03T15:05:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AStupidBear](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@AStupidBear](https://discourse.julialang.org/u/AStupidBear)\
**Post date:** [April 3, 2017, 3:05pm UTC](https://discourse.julialang.org/t/bug-of-replace/3023/1 "2017-04-03T15:05:40Z")

</div>

`replace("123\n", r"(\n)", s"\1")` is OK, but `replace("123\n", r"(\n)", s"\r\1")` reports “Bad replacement string”. Is this a bug of function `replace`?

---

<div class="post-metadata">

**Author:** ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Post date:** [April 5, 2017, 1:28am UTC](https://discourse.julialang.org/t/bug-of-replace/3023/2 "2017-04-05T01:28:51Z")

</div>

It might be considered a bug in the string literal for `SubstitutionString`:

The following works, where the `SubstitutionString` is created directly:

(Note that below `\1` is displayed as `\l` because discourse markdown renders as a backtick, and I don’t know how to escape it)

```julia
Julia-0.5.1> s = Base.SubstitutionString("\r\\l")
s"\r\\l"

```

```julia
Julia-0.5.1> replace("123\n", r"(\n)", s)
"123\r\n"

```

It appears that `s"\r\1"` creates a 4-character string `"\\r\\l"`, rather than the 3-character string `"\r\\l"`.

Perhaps file an issue?

---

<div class="post-metadata">

**Author:** ![AStupidBear](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@AStupidBear](https://discourse.julialang.org/u/AStupidBear)\
**Post date:** [April 5, 2017, 6:19am UTC](https://discourse.julialang.org/t/bug-of-replace/3023/3 "2017-04-05T06:19:06Z")

</div>

Thanks
