# Substring in painless

**URL:** <https://discuss.elastic.co/t/substring-in-painless/88660>\
**Category:** Elasticsearch\
**Created:** [June 8, 2017, 6:34am UTC](https://discuss.elastic.co/t/substring-in-painless/88660 "2017-06-08T06:34:26Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [June 9, 2017, 3:24pm UTC](https://discuss.elastic.co/t/substring-in-painless/88660/3 "2017-06-09T15:24:46Z")

</div>

If you are trying to use a regex, I think it would look something like:

```auto
Matcher match = /([^\?]+).*/.matcher(doc['request'].value);
if (match.matches()) {
  return match.group(1);
} else {
  // something is wrong? the path is malformed, decide what to return or throw an error
}

```

---

_[View the full topic](https://discuss.elastic.co/t/substring-in-painless/88660)._
