# Backslash in the if statement - LogStash

**URL:** <https://discuss.elastic.co/t/backslash-in-the-if-statement-logstash/151292>\
**Category:** Logstash\
**Created:** [October 6, 2018, 3:15am UTC](https://discuss.elastic.co/t/backslash-in-the-if-statement-logstash/151292 "2018-10-06T03:15:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![VietCong](https://avatars.discourse-cdn.com/v4/letter/v/e47774/32.png) [@VietCong](https://discuss.elastic.co/u/VietCong)\
**Post date:** [October 6, 2018, 3:15am UTC](https://discuss.elastic.co/t/backslash-in-the-if-statement-logstash/151292/1 "2018-10-06T03:15:49Z")

</div>

Hi, I would like to know how to write an if statement with the condition of a (backslash) being in the string like below:

if ( \backslash\ in [field1] ) {  
Do\_something {}  
}

I have tried:

- if ( "\" in [field1] ) {}
- if ( [\] in [field1] ) {}

but none of it works. I feel like the second option is very close to what works but I dont know the exact syntax. Could somebody help?

---

<div class="post-metadata">

**Author:** ![kabilan](https://avatars.discourse-cdn.com/v4/letter/k/ecccb3/32.png) [@kabilan](https://discuss.elastic.co/u/kabilan)\
**Post date:** [October 6, 2018, 7:15am UTC](https://discuss.elastic.co/t/backslash-in-the-if-statement-logstash/151292/2 "2018-10-06T07:15:48Z")

</div>

if [\\] in [field1]  
{}

try without the parentheses, let me know if that works

---

<div class="post-metadata">

**Author:** ![VietCong](https://avatars.discourse-cdn.com/v4/letter/v/e47774/32.png) [@VietCong](https://discuss.elastic.co/u/VietCong)\
**Post date:** [October 6, 2018, 8:43am UTC](https://discuss.elastic.co/t/backslash-in-the-if-statement-logstash/151292/3 "2018-10-06T08:43:31Z")

</div>

Thanks for your response. this doesnt work

---

<div class="post-metadata">

**Author:** ![VietCong](https://avatars.discourse-cdn.com/v4/letter/v/e47774/32.png) [@VietCong](https://discuss.elastic.co/u/VietCong)\
**Post date:** [October 6, 2018, 9:44am UTC](https://discuss.elastic.co/t/backslash-in-the-if-statement-logstash/151292/4 "2018-10-06T09:44:50Z")

</div>

so eventually, I found the solution with regex, probably not the perfect solution but it works at the moment for me:

if [field1] =~ /^.+\.+$/ {

}

---

<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:** [November 3, 2018, 9:45am UTC](https://discuss.elastic.co/t/backslash-in-the-if-statement-logstash/151292/5 "2018-11-03T09:45:10Z")

</div>

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