# Regex not working for translate filter

**URL:** https://discuss.elastic.co/t/regex-not-working-for-translate-filter/44231
**Category:** Logstash
**Created:** [March 12, 2016, 1:46pm UTC](https://discuss.elastic.co/t/regex-not-working-for-translate-filter/44231 "2016-03-12T13:46:58Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![bharath\_meka](https://avatars.discourse-cdn.com/v4/letter/b/858c86/32.png) [@bharath\_meka](https://discuss.elastic.co/u/bharath_meka)
#### Post date: [March 12, 2016, 1:46pm UTC](https://discuss.elastic.co/t/regex-not-working-for-translate-filter/44231/1 "2016-03-12T13:46:58Z")

</div>

Hi,

I'm trying to add a translate filter to parse a field using regex and populate a destination based on the value. If it is a direct text match it is working fine. But with regex it is always going to fallback value.

I'm trying to match the following packages with the translate filter.  
_com.xxx.flowapi.abc_  
_com.xxx.prs.abc_

Here is the code snippet. If I use the complete package name it works but if I use regex as below it always goes to the fallback value. Am I missing something here?

> ```
> translate {  
> regex => true
> field => "package"
> destination => "subtype"
> fallback => "unknown_subtype"
> dictionary => [ "/prs/", "prs",
> "/flowapi/", "dwflowapi"
> ]
> }
> 
> ```

Regards,  
Bharath

---

<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: [March 15, 2016, 9:26pm UTC](https://discuss.elastic.co/t/regex-not-working-for-translate-filter/44231/2 "2016-03-15T21:26:51Z")

</div>

I'm pretty sure you're not supposed to surround your regular expression with slashes.

---

<div class="post-metadata">

### Author: ![Pablo\_Gonzalez](https://avatars.discourse-cdn.com/v4/letter/p/3be4f8/32.png) [@Pablo\_Gonzalez](https://discuss.elastic.co/u/Pablo_Gonzalez)
#### Post date: [May 30, 2016, 2:19am UTC](https://discuss.elastic.co/t/regex-not-working-for-translate-filter/44231/3 "2016-05-30T02:19:59Z")

</div>

From the translate plugin documentation:

If you’d like to treat dictionary keys as regular expressions, set exact =\> true. Note: this is activated only when exact =\> true.

Worked for me.

---

<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:55am UTC](https://discuss.elastic.co/t/regex-not-working-for-translate-filter/44231/4 "2017-07-06T04:55:37Z")

</div>


