# Gsub doesn't replace the given char

**URL:** https://discuss.elastic.co/t/gsub-doesnt-replace-the-given-char/280783
**Category:** Logstash
**Created:** [August 9, 2021, 9:20am UTC](https://discuss.elastic.co/t/gsub-doesnt-replace-the-given-char/280783 "2021-08-09T09:20:31Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![vaseemQA](https://avatars.discourse-cdn.com/v4/letter/v/4491bb/32.png) [@vaseemQA](https://discuss.elastic.co/u/vaseemQA)
#### Post date: [August 9, 2021, 9:20am UTC](https://discuss.elastic.co/t/gsub-doesnt-replace-the-given-char/280783/1 "2021-08-09T09:20:31Z")

</div>

Hi Team,

I'm trying to replace a char with another char in a string field, but it doesn't looks like it is doing the job, please is there anyone to help me in correcting this.

Here is an example of what I'm doing ,

```auto
"source_query": "{\"from\":0,\"size\":10,\"query\":{\"bool\":{\"must\":[{\"query_string\":{\"query\":\"(\\\"testData\\\"^20.000000 OR testData*^10.000000 OR *testData*) AND (\\\"testData\\\\:\\\"^20.000000 OR testData\\\\:*^10.000000 OR *testData\\\\:*) AND (\\\"testData\\\"^20.000000 OR testData*^10.000000 OR *testData*)\",\"fields\":[\"testOrder.contactPhones^1.0\",\"testOrder.personPhones^1.0\",\"ownerOrder.contactPhones^1.0\",\"ownerOrder.xxxxxxxxPhones^1.0\",\"globalCopyField^1.0\",\"p0AttrCopyField^1.8\",\"phone^1.0\"],\"type\":\"best_fields\",\"default_operator\":\"or\",\"max_determinized_states\":10000,\"enable_position_increments\":true,\"fuzziness\":\"AUTO\",\"fuzzy_prefix_length\":0,\"fuzzy_max_expansions\":50,\"phrase_slop\":0,\"escape\":false,\"auto_generate_synonyms_phrase_query\":true,\"fuzzy_transpositions\":true,\"boost\":1.0}}],\"filter\":[{\"bool\":{\"must\":[{\"terms\":{\"contextType\":[\"testData\"],\"boost\":1.0}},{\"term\":{\"active\":{\"value\":true,\"boost\":1.0}}},{\"term\":{\"deleted\":{\"value\":false,\"boost\":1.0}}},{\"bool\":{\"should\":[{\"term\":{\"requiredOrderId\":{\"value\":testData,\"boost\":1.0}}}],\"adjust_pure_negative\":true,\"boost\":1.0}}],\"adjust_pure_negative\":true,\"boost\":1.0}}],\"adjust_pure_negative\":true,\"boost\":1.0}},\"version\":true,\"sort\":[{\"_score\":{\"order\":\"desc\"}},{\"updatedAt\":{\"order\":\"desc\",\"missing\":\"_last\",\"unmapped_type\":\"long\"}},{\"createdAt\":{\"order\":\"desc\",\"missing\":\"_last\",\"unmapped_type\":\"long\"}}]}"

```

trying to replace " with " using gsub like below

```auto
mutate{
                gsub => ["source_query","\\\"","\""]
              }

```

Thanks,  
Vaseem

---

<div class="post-metadata">

### Author: ![Cad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cad/32/86661_2.png) [@Cad](https://discuss.elastic.co/u/Cad)
#### Post date: [August 9, 2021, 1:02pm UTC](https://discuss.elastic.co/t/gsub-doesnt-replace-the-given-char/280783/2 "2021-08-09T13:02:43Z")

</div>

Hi,

You are trying to replace a value by herself.  
Indeed, in a string `\"` is print `\\\"`.  
If you want to remove all `\` use this :

```auto
mutate {
  gsub => [
    "source_query", "[\\]+[\"]", '"' # one double quote between two single quote
  ]
}

```

Cad.

---

<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: [September 6, 2021, 1:03pm UTC](https://discuss.elastic.co/t/gsub-doesnt-replace-the-given-char/280783/3 "2021-09-06T13:03:31Z")

</div>

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