# Split string

**URL:** <https://discuss.elastic.co/t/split-string/189310>\
**Category:** Kibana\
**Created:** [July 8, 2019, 8:38am UTC](https://discuss.elastic.co/t/split-string/189310 "2019-07-08T08:38:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yagami23](https://avatars.discourse-cdn.com/v4/letter/y/e19adc/32.png) [@yagami23](https://discuss.elastic.co/u/yagami23)\
**Post date:** [July 8, 2019, 8:38am UTC](https://discuss.elastic.co/t/split-string/189310/1 "2019-07-08T08:38:08Z")

</div>

Example:  
/opt/apps/logs/engineering-ext/niwp/NiWpPerformance.log

i want to get the substring 'engineering-ext' & 'niwp', how can i get it in scripted field using painless.

---

<div class="post-metadata">

**Author:** ![joshdover](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joshdover/32/42020_2.png) [@joshdover](https://discuss.elastic.co/u/joshdover)\
**Post date:** [July 8, 2019, 2:30pm UTC](https://discuss.elastic.co/t/split-string/189310/2 "2019-07-08T14:30:02Z")

</div>

You'll want use a regular expression for this. Something close to this should work:

```auto
def m = /opt\/apps\/logs\/([a-z\-]+)\/([a-z\-]+)\/.*/.matcher(doc['my_field_name'].value)

return m.group(1) + m.group(2)

```

See [the Matcher docs](https://docs.oracle.com/javase/8/docs/api/java/util/regex/Matcher.html) for more information on how to use this class.

---

<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 5, 2019, 2:30pm UTC](https://discuss.elastic.co/t/split-string/189310/3 "2019-08-05T14:30:09Z")

</div>

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