# Reading regex from file in a filter

**URL:** <https://discuss.elastic.co/t/reading-regex-from-file-in-a-filter/224724>\
**Category:** Logstash\
**Created:** [March 23, 2020, 8:13pm UTC](https://discuss.elastic.co/t/reading-regex-from-file-in-a-filter/224724 "2020-03-23T20:13:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mnrdammu](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@mnrdammu](https://discuss.elastic.co/u/mnrdammu)\
**Post date:** [March 23, 2020, 8:13pm UTC](https://discuss.elastic.co/t/reading-regex-from-file-in-a-filter/224724/1 "2020-03-23T20:13:07Z")

</div>

I created a log stash filter plugin which runs the regex match against a field, and if it matches, create a new field 'flag' and sets the value as 'Y'  
Currently I am using the regex inside the ruby file of my filter but ideally I have to read the regex from some file , as this regex is gonna be a huge string.

This is how my filter code looks like now  
`def filter(event)`

```
    `if @message`
      `products = event.get("products")`
	  `if ( products =~ /apple(?:ipad|laptop|watch)?|nike(?:jersey|shoes)?/ )`
		`event.set("flag", 'Y')`
	 ` end `
   ` end`

   ` filter_matched(event)`
` end `

```

` end`

Kindly guide me on how to proceed on this further.

---

<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:** [April 20, 2020, 8:13pm UTC](https://discuss.elastic.co/t/reading-regex-from-file-in-a-filter/224724/2 "2020-04-20T20:13:14Z")

</div>

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