# Removing characters from String

**URL:** <https://discourse.julialang.org/t/removing-characters-from-string/53962>\
**Category:** General Usage\
**Tags:** strings\
**Created:** [January 26, 2021, 9:42am UTC](https://discourse.julialang.org/t/removing-characters-from-string/53962 "2021-01-26T09:42:27Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [January 26, 2021, 12:41pm UTC](https://discourse.julialang.org/t/removing-characters-from-string/53962/12 "2021-01-26T12:41:37Z")

</div>

If you just want to work on bytes you should use `codeunits` instead of `collect`:

```julia
str = "aa <12> bb <c> ąą <123> dd"
r = r"<.+?>"
mask = BitArray((0, 1, 1))
matches = collect(eachmatch(r, str))[mask]
ranges_to_remove = [m.offset:(m.offset + sizeof(m.match)) for m in matches]
ranges_to_keep = setdiff(1:sizeof(str), reduce(vcat, ranges_to_remove))
String(codeunits(str)[ranges_to_keep])

# "aa <12> bb ąą dd"

```

---

_[View the full topic](https://discourse.julialang.org/t/removing-characters-from-string/53962)._
