# Watcher - Transform - Painless - Regular Expression / Regex - Documentation Issue?

**URL:** <https://discuss.elastic.co/t/watcher-transform-painless-regular-expression-regex-documentation-issue/90661>\
**Category:** Elasticsearch\
**Created:** [June 23, 2017, 3:25pm UTC](https://discuss.elastic.co/t/watcher-transform-painless-regular-expression-regex-documentation-issue/90661 "2017-06-23T15:25:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![brommer](https://avatars.discourse-cdn.com/v4/letter/b/65b543/32.png) [@brommer](https://discuss.elastic.co/u/brommer)\
**Post date:** [June 23, 2017, 3:25pm UTC](https://discuss.elastic.co/t/watcher-transform-painless-regular-expression-regex-documentation-issue/90661/1 "2017-06-23T15:25:56Z")

</div>

Hi there,

at [https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-painless.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-painless.html) you show some examples of how to use regex in a painless script. In those examples you are never using m.matches() before you call "group" or "replaceAll". I ran into a really confusing issue today, where without calling "matches" before I was not having any matching result. Is the documentation wrong or should it really be working without calling "matches" beforhands.

If it should be working without "matches", following script did not return any match to me:

```auto
    "transform" : {
      "script" : {
        "inline" : "ctx.payload.action = /(.*)/.matcher('action'); return ctx.payload"
      }
    }

```

```auto
"action": "java.util.regex.Matcher[pattern=(.*) region=0,6 lastmatch=]",

```

Thanks!  
Andreas

---

<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:** [June 23, 2017, 6:57pm UTC](https://discuss.elastic.co/t/watcher-transform-painless-regular-expression-regex-documentation-issue/90661/2 "2017-06-23T18:57:11Z")

</div>

Hey,

not sure I got your example right, just tried this, and it works

```auto
"ctx.payload.action = /foo (.*) bar/.matcher(ctx.payload.action).replaceAll('$1'); return ctx.payload"

```

is this what you want to do? `matches()` will only return a boolean, if it matches, but nothing more.

Hope this helps. If not, a fully fledged example within the execute watch API would be awesome!

--Alex

---

<div class="post-metadata">

**Author:** ![brommer](https://avatars.discourse-cdn.com/v4/letter/b/65b543/32.png) [@brommer](https://discuss.elastic.co/u/brommer)\
**Post date:** [June 26, 2017, 8:08am UTC](https://discuss.elastic.co/t/watcher-transform-painless-regular-expression-regex-documentation-issue/90661/3 "2017-06-26T08:08:51Z")

</div>

Thanks, you are right. I confused "replaceAll" and "group".

---

<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:** [July 24, 2017, 8:17am UTC](https://discuss.elastic.co/t/watcher-transform-painless-regular-expression-regex-documentation-issue/90661/4 "2017-07-24T08:17:10Z")

</div>

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