# How to parse the below scenario?

**URL:** <https://discuss.elastic.co/t/how-to-parse-the-below-scenario/188928>\
**Category:** Logstash\
**Created:** [July 4, 2019, 2:18pm UTC](https://discuss.elastic.co/t/how-to-parse-the-below-scenario/188928 "2019-07-04T14:18:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Debashis\_Adak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/debashis_adak/32/46087_2.png) [@Debashis\_Adak](https://discuss.elastic.co/u/Debashis_Adak)\
**Post date:** [July 4, 2019, 2:18pm UTC](https://discuss.elastic.co/t/how-to-parse-the-below-scenario/188928/1 "2019-07-04T14:18:38Z")

</div>

Hi All,

Please find the below mentioned inputs

1. /abcd/efgh/yj/kl/mn/op
2. abcd/efgh/yj/kl/mn/op
3. abcd
4. /abcd
5. abcd/

Output Required: servicename = abcd

I have tried two grok parser

1. (/)?%{DATA:servicename}/ ==\> Making last / mandatory
2. (/)?%{DATA:servicename}(/)? ==\> Nothing is coming in servicename field

Can you please help me regarding the same?

Regards,  
Debashis

---

<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:** [July 4, 2019, 2:32pm UTC](https://discuss.elastic.co/t/how-to-parse-the-below-scenario/188928/2 "2019-07-04T14:32:02Z")

</div>

That is very strange!

You can use

```
grok { match => { "message" => "^(/)?(?<servicename>[^/]+)(/)?" } }
```

---

<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:** [August 1, 2019, 2:32pm UTC](https://discuss.elastic.co/t/how-to-parse-the-below-scenario/188928/3 "2019-08-01T14:32:07Z")

</div>

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