# Looking for ideas to mask part of a creditcard

**URL:** <https://discuss.elastic.co/t/looking-for-ideas-to-mask-part-of-a-creditcard/166333>\
**Category:** Logstash\
**Created:** [January 30, 2019, 10:38am UTC](https://discuss.elastic.co/t/looking-for-ideas-to-mask-part-of-a-creditcard/166333 "2019-01-30T10:38:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saurav\_Sen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/saurav_sen/32/54025_2.png) [@Saurav\_Sen](https://discuss.elastic.co/u/Saurav_Sen)\
**Post date:** [January 30, 2019, 10:38am UTC](https://discuss.elastic.co/t/looking-for-ideas-to-mask-part-of-a-creditcard/166333/1 "2019-01-30T10:38:03Z")

</div>

Trying to mask out a part (6-10th digit) of the 16 digit credit card.

1234567898763456 to 1234######3456

I can think of using gsub filter, but I can't find a way to match the exact section of numbers.

The option would be to split in various sections and then gsub the whole field to '#' and then join back, seems too much work. Any suggestions.

Something like this will mask the whole thing, which i don't want.

```auto
filter
{
  mutate {
    gsub => [
      "message","[0-9]{16}","################"   
    ]
  }
}

```

---

<div class="post-metadata">

**Author:** ![danhermann](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danhermann/32/33024_2.png) [@danhermann](https://discuss.elastic.co/u/danhermann)\
**Post date:** [January 30, 2019, 11:46am UTC](https://discuss.elastic.co/t/looking-for-ideas-to-mask-part-of-a-creditcard/166333/2 "2019-01-30T11:46:49Z")

</div>

@Saurav_Sen, using regex capture groups along the lines of the example below should work for you:

```auto
filter
{
  mutate {
    gsub => [
      "message","([0-9]{5})([0-9]{5})([0-9]{6})", "\1#####\3"
    ]
  }
}

```

---

<div class="post-metadata">

**Author:** ![Saurav\_Sen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/saurav_sen/32/54025_2.png) [@Saurav\_Sen](https://discuss.elastic.co/u/Saurav_Sen)\
**Post date:** [January 31, 2019, 3:35am UTC](https://discuss.elastic.co/t/looking-for-ideas-to-mask-part-of-a-creditcard/166333/3 "2019-01-31T03:35:28Z")

</div>

Thanks a lot @danhermann, i tweaked it a bit to get the combination I wanted.works great

eg:  
9999999999999999 to 999999######9999

```
filter {
    mutate {
    gsub => [
      "message","([0-9]{6})([0-9]{6})([0-9]{4})", "\1######\3"
    ]
  }
}
```

---

<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:** [February 28, 2019, 3:35am UTC](https://discuss.elastic.co/t/looking-for-ideas-to-mask-part-of-a-creditcard/166333/4 "2019-02-28T03:35:32Z")

</div>

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