# Match and Replace unicode characters?

**URL:** <https://discuss.elastic.co/t/match-and-replace-unicode-characters/56656>\
**Category:** Logstash\
**Created:** [July 28, 2016, 5:01pm UTC](https://discuss.elastic.co/t/match-and-replace-unicode-characters/56656 "2016-07-28T17:01:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maxwell\_Flanders](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@Maxwell\_Flanders](https://discuss.elastic.co/u/Maxwell_Flanders)\
**Post date:** [July 28, 2016, 5:01pm UTC](https://discuss.elastic.co/t/match-and-replace-unicode-characters/56656/1 "2016-07-28T17:01:31Z")

</div>

I am attempting to perform a gsub on a unicode character, and sub it out with something else. However, I'm having trouble matching it. The unicode character is \uFFFD (from [http://www.ssec.wisc.edu/~tomw/java/unicode.html#x0000](http://www.ssec.wisc.edu/~tomw/java/unicode.html#x0000), the very last item on the page, specifically used as a replacement character). My logstash code to replace it looks like this:

```
ruby {
    code => "
        event.to_hash.each { |k,v|
            v.gsub!('\uFFFD', 'replaceWithThis') if v.is_a?(String)
        }
    "
}

```

Which has worked for me for other replacements, but I can't seem to match the unicode character. I've also tried it with a double escape slash with no luck. Any ideas on how I could get this substitution to match??

---

<div class="post-metadata">

**Author:** ![Maxwell\_Flanders](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@Maxwell\_Flanders](https://discuss.elastic.co/u/Maxwell_Flanders)\
**Post date:** [July 29, 2016, 6:20pm UTC](https://discuss.elastic.co/t/match-and-replace-unicode-characters/56656/2 "2016-07-29T18:20:47Z")

</div>

I have found the solution, I had to change my code to look like:

```
ruby {
    code => "
        event.to_hash.each { |k,v|
            v.gsub!(/\uFFFD/, 'replaceWithThis') if v.is_a?(String)
        }
    "
}

```

and it matched the character correctly.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 4:45am UTC](https://discuss.elastic.co/t/match-and-replace-unicode-characters/56656/3 "2017-07-06T04:45:53Z")

</div>


