# Inclusion and regex on conditionals

**URL:** <https://discuss.elastic.co/t/inclusion-and-regex-on-conditionals/232756>\
**Category:** Logstash\
**Created:** [May 15, 2020, 5:24am UTC](https://discuss.elastic.co/t/inclusion-and-regex-on-conditionals/232756 "2020-05-15T05:24:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElasticLiver](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticliver/32/64869_2.png) [@ElasticLiver](https://discuss.elastic.co/u/ElasticLiver)\
**Post date:** [May 15, 2020, 5:25am UTC](https://discuss.elastic.co/t/inclusion-and-regex-on-conditionals/232756/1 "2020-05-15T05:25:00Z")

</div>

This will match the exact match of "SCD" or will also match "scd" or "SCD-abc"? works like a linux grep?

```auto
        if [hostgroup] =~ /SCD/ { mutate { add_field => { "indexname" => "scd" }}}

```

What is the diference with:

```auto
        if [SCD] in [hostgroup] { mutate { add_field => { "indexname" => "scd" }}}

```

again, this will match "scd" or "SCD-abc"?

Thanks!

---

<div class="post-metadata">

**Author:** ![hunsw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hunsw/32/93637_2.png) [@hunsw](https://discuss.elastic.co/u/hunsw)\
**Post date:** [May 15, 2020, 6:28am UTC](https://discuss.elastic.co/t/inclusion-and-regex-on-conditionals/232756/2 "2020-05-15T06:28:39Z")

</div>

If I were you, I'd check an online regex tester and maybe read some articles about it.

Java uses a Perl-like regex engine, so for basic functionality like yours, any PCRE tester should work.

grep -P uses PCRE too, so you can test with that (or with Logstash too 🙂 )

As for the **in** expression, to quote the documentation:

> You can use the `in` operator to test whether a field contains a specific string, key, or (for lists) element.

To answer your specific question wrt the specific regex:  
`/SCD/` won't match **scd** , but should match the SCD in **SCD-abc**.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [May 15, 2020, 3:29pm UTC](https://discuss.elastic.co/t/inclusion-and-regex-on-conditionals/232756/3 "2020-05-15T15:29:54Z")

</div>

> [@hunsw](#):
>
> Java uses a Perl-like regex engine

logstash uses ruby regexps.

---

<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:** [June 12, 2020, 3:30pm UTC](https://discuss.elastic.co/t/inclusion-and-regex-on-conditionals/232756/4 "2020-06-12T15:30:01Z")

</div>

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