# Trying to gsub with regex and seeing character encoding error

**URL:** <https://discuss.elastic.co/t/trying-to-gsub-with-regex-and-seeing-character-encoding-error/184647>\
**Category:** Logstash\
**Created:** [June 6, 2019, 6:38pm UTC](https://discuss.elastic.co/t/trying-to-gsub-with-regex-and-seeing-character-encoding-error/184647 "2019-06-06T18:38:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![az123](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@az123](https://discuss.elastic.co/u/az123)\
**Post date:** [June 6, 2019, 6:38pm UTC](https://discuss.elastic.co/t/trying-to-gsub-with-regex-and-seeing-character-encoding-error/184647/1 "2019-06-06T18:38:04Z")

</div>

I am trying to parse json coming over a tcp port. I noticed json parse errors and it looks like its due to some non-json strings in the input stream. I then crafted a regexp that matches these spurious messages and tried to gsub it with "" string so that only pure json is left behind. Now, I am seeing this error:

[DEBUG] 2019-06-06 18:29:19.472 [nioEventLoopGroup-2-1] ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@44f418a3

[ERROR] 2019-06-06 18:29:19.617 [nioEventLoopGroup-2-1] tcp - Error in Netty pipeline: org.jruby.exceptions.EncodingError$CompatibilityError: (CompatibilityError) incompatible character encodings: ASCII-8BIT and UTF-8

I tried to substitute the char encoding as shown below but it does not help:

input {  
tcp {  
port =\> 48203  
codec =\> json\_lines { charset =\> "UTF-8"  
delimiter =\> "\\\w+[0-9.'ɰ]?" }

}  
}  
filter {  
mutate {  
gsub =\> ["fieldname", "\\\w+[0-9.'ɰ]?", "" ]  
}  
}

---

<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 4, 2019, 6:38pm UTC](https://discuss.elastic.co/t/trying-to-gsub-with-regex-and-seeing-character-encoding-error/184647/2 "2019-07-04T18:38:10Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
