# Substring in watcher action

**URL:** <https://discuss.elastic.co/t/substring-in-watcher-action/146550>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [August 29, 2018, 3:11pm UTC](https://discuss.elastic.co/t/substring-in-watcher-action/146550 "2018-08-29T15:11:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheCodingKnight](https://avatars.discourse-cdn.com/v4/letter/t/35a633/32.png) [@TheCodingKnight](https://discuss.elastic.co/u/TheCodingKnight)\
**Post date:** [August 29, 2018, 3:11pm UTC](https://discuss.elastic.co/t/substring-in-watcher-action/146550/1 "2018-08-29T15:11:12Z")

</div>

Hi,  
I've created a watcher which monitors for the keywords "result address" and returns the following line. Is there a way to extract the "doorno" part out of this line to display in an email through the watcher action?

`"The result address is /continent/country/province/county/city/street/doorno"`

Tried playing around with Moustache, that didn't seem to help thou'. Any other pointers?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 31, 2018, 9:19am UTC](https://discuss.elastic.co/t/substring-in-watcher-action/146550/2 "2018-08-31T09:19:39Z")

</div>

Hey,

check out this example

```auto
POST _xpack/watcher/watch/_execute
{
  "watch": {
    "trigger": {
      "schedule": {
        "interval": "10h"
      }
    },
    "input": {
      "simple": {
        "foo": " /continent/country/province/county/city/street/doorno"
      }
    },
    "actions": {
      "logme": {
        "transform" : {
          "script": "def lastSlashPosition = ctx.payload.foo.lastIndexOf('/') ; return ctx.payload.foo.substring(lastSlashPosition+1)"
        },
        "logging": {
          "text": "{{ctx.payload}}"
        }
      }
    }
  }
}

```

note, that the transformation is super simple and not fool proof. There are no boundary checks (last character being a slash for example), but it should get you started.

--Alex

---

<div class="post-metadata">

**Author:** ![TheCodingKnight](https://avatars.discourse-cdn.com/v4/letter/t/35a633/32.png) [@TheCodingKnight](https://discuss.elastic.co/u/TheCodingKnight)\
**Post date:** [August 31, 2018, 11:07am UTC](https://discuss.elastic.co/t/substring-in-watcher-action/146550/3 "2018-08-31T11:07:32Z")

</div>

Thanks. Will give it a try now.

---

<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:** [September 28, 2018, 11:07am UTC](https://discuss.elastic.co/t/substring-in-watcher-action/146550/4 "2018-09-28T11:07:32Z")

</div>

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