# Logstash gsub filter with special characters not working

**URL:** <https://discuss.elastic.co/t/logstash-gsub-filter-with-special-characters-not-working/131057>\
**Category:** Logstash\
**Created:** [May 8, 2018, 8:06pm UTC](https://discuss.elastic.co/t/logstash-gsub-filter-with-special-characters-not-working/131057 "2018-05-08T20:06:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chakriv](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@chakriv](https://discuss.elastic.co/u/chakriv)\
**Post date:** [May 8, 2018, 8:06pm UTC](https://discuss.elastic.co/t/logstash-gsub-filter-with-special-characters-not-working/131057/1 "2018-05-08T20:06:11Z")

</div>

hello all,

I am currently running logstash 6.x with ES 6.x and i am trying to leverage logstash to parse through the data and using mutate and gsub filters

i have a syslog\_msg in the current format 🙂

example(): {"token”:”sdssfsfsfs”,”expires":"2018-04-27T08:01:22.405Z"}

i am trying to leverage gsub filter to remove example from this string so that it's a json struct to do further conversion to grab token and expiration fields

here is my filter conf 🙂

filter {

if [logsource] =~ "example-service" {

```
mutate {
  gsub => ["syslog_msg" , "example():" , ""]
}
json {
  source => "syslog_msg"
  target => "parsedJsonmsg"
  tag_on_failure => ["_jsonparsefailure"]
  } 

```

}  
}

any help appreciated i have tried multiple combinations of example() and trying to see if there is a better way to do this

thanks  
CHakri

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [May 8, 2018, 8:17pm UTC](https://discuss.elastic.co/t/logstash-gsub-filter-with-special-characters-not-working/131057/2 "2018-05-08T20:17:10Z")

</div>

Parentheses have a special meaning in regexps so you need to escape them. You should also start the expression with `^` so it only matches at the beginning of the line.

---

<div class="post-metadata">

**Author:** ![chakriv](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@chakriv](https://discuss.elastic.co/u/chakriv)\
**Post date:** [May 8, 2018, 9:42pm UTC](https://discuss.elastic.co/t/logstash-gsub-filter-with-special-characters-not-working/131057/3 "2018-05-08T21:42:37Z")

</div>

thanks so much.it worked like a charm 🙂

---

<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:** [June 5, 2018, 9:42pm UTC](https://discuss.elastic.co/t/logstash-gsub-filter-with-special-characters-not-working/131057/4 "2018-06-05T21:42:39Z")

</div>

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