# If statement not working with gsub

**URL:** https://discuss.elastic.co/t/if-statement-not-working-with-gsub/215030
**Category:** Logstash
**Created:** [January 14, 2020, 6:27pm UTC](https://discuss.elastic.co/t/if-statement-not-working-with-gsub/215030 "2020-01-14T18:27:39Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![andres-perez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andres-perez/32/136461_2.png) [@andres-perez](https://discuss.elastic.co/u/andres-perez)
#### Post date: [January 15, 2020, 11:36am UTC](https://discuss.elastic.co/t/if-statement-not-working-with-gsub/215030/4 "2020-01-15T11:36:51Z")

</div>

Well, I would say that is the most frequent case:  
`if [field] in ["apples","oranges","pineapples"] { # looks for exact match between the complete field and any of the array elements `

but, checking carefully the documentation on conditionals: [https://www.elastic.co/guide/en/logstash/current/event-dependent-configuration.html#conditionals](https://www.elastic.co/guide/en/logstash/current/event-dependent-configuration.html#conditionals)  
It also allows looking for "string in field", equivalent to the regex example you posted.

`if "apple" in [field] { # will match both "apples" and "pineapples"`

I would add that, working with `in` conditionals, there is a **bug** that has to be taken into account: one-element array comparison doesn't work.

`if [field] in ["apples"] { # won't match even if field = "apples"`

> <https://github.com/elastic/logstash/issues/5591>
>
> Version:
> Ubuntu 16.04 LTS
> Logstash 2.3.2
> Hi
> I have found that multiple people ran into the issue where the in check gets confused as to...

* * *

@nino  
Thanks for adding your working configuration 🙂

---

_[View the full topic](https://discuss.elastic.co/t/if-statement-not-working-with-gsub/215030)._
