# Kibana Scripted - How to get a string between the second and the third slash

**URL:** <https://discuss.elastic.co/t/kibana-scripted-how-to-get-a-string-between-the-second-and-the-third-slash/264188>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [February 12, 2021, 9:51pm UTC](https://discuss.elastic.co/t/kibana-scripted-how-to-get-a-string-between-the-second-and-the-third-slash/264188 "2021-02-12T21:51:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![linfordwoode](https://avatars.discourse-cdn.com/v4/letter/l/5fc32e/32.png) [@linfordwoode](https://discuss.elastic.co/u/linfordwoode)\
**Post date:** [February 12, 2021, 9:51pm UTC](https://discuss.elastic.co/t/kibana-scripted-how-to-get-a-string-between-the-second-and-the-third-slash/264188/1 "2021-02-12T21:51:47Z")

</div>

Hey Guys, I am trying to get a string from a file path field in Kibana. I am not quite sure how to go about it.

```auto
C:/path/[application]/file.log. 

```

The first two slashes are constant however, the slashes after [application] can be dynamic. For example, it can be

```auto
C:/path/[application]/v/2/file.log

```

I want to extract [application] from the file paths.

Thanks for the help

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [February 12, 2021, 11:09pm UTC](https://discuss.elastic.co/t/kibana-scripted-how-to-get-a-string-between-the-second-and-the-third-slash/264188/2 "2021-02-12T23:09:56Z")

</div>

One way is to split on `/` and return the 3rd element.

`C:/path/[application]/file.log`  
`0_/1 ___/2____________ /3 _______ `

**Script**

```auto
String[] parts = /\//.split("C:/path/[application]/file.log");

return parts[2];

```

**Outputs**

```auto
[application]

```

---

<div class="post-metadata">

**Author:** ![linfordwoode](https://avatars.discourse-cdn.com/v4/letter/l/5fc32e/32.png) [@linfordwoode](https://discuss.elastic.co/u/linfordwoode)\
**Post date:** [February 15, 2021, 2:36pm UTC](https://discuss.elastic.co/t/kibana-scripted-how-to-get-a-string-between-the-second-and-the-third-slash/264188/3 "2021-02-15T14:36:18Z")

</div>

Thanks Aaron, I have tried using this script but it is not working for me. Is there anything I am doing wrong here?

```auto
def path = doc['log.file.path'].value;
String[] parts = path.split("\\/");
return parts[2];

```

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [February 15, 2021, 7:34pm UTC](https://discuss.elastic.co/t/kibana-scripted-how-to-get-a-string-between-the-second-and-the-third-slash/264188/4 "2021-02-15T19:34:59Z")

</div>

Try this.

```auto
String[] parts = /\//.split(doc['log.file.path'].value);
return parts[2];

```

---

<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:** [March 15, 2021, 7:35pm UTC](https://discuss.elastic.co/t/kibana-scripted-how-to-get-a-string-between-the-second-and-the-third-slash/264188/5 "2021-03-15T19:35:33Z")

</div>

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