# Regex Expression: ignore all characters and match only the last word in the message field

**URL:** <https://discuss.elastic.co/t/regex-expression-ignore-all-characters-and-match-only-the-last-word-in-the-message-field/173514>\
**Category:** Elasticsearch\
**Created:** [March 22, 2019, 3:06pm UTC](https://discuss.elastic.co/t/regex-expression-ignore-all-characters-and-match-only-the-last-word-in-the-message-field/173514 "2019-03-22T15:06:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anonymous2](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@Anonymous2](https://discuss.elastic.co/u/Anonymous2)\
**Post date:** [March 22, 2019, 3:06pm UTC](https://discuss.elastic.co/t/regex-expression-ignore-all-characters-and-match-only-the-last-word-in-the-message-field/173514/1 "2019-03-22T15:06:59Z")

</div>

Hello, I've created a query in wich I want to use a regex expression.

```
GET tpms-system/_search
{
    "aggs": {
        "dashbord_updates": {
            "terms": {
              "field" : "message",
              "include": "<some regex exp>"
            }
        }
    }
}

```

I want to ignore all characters and match only the last word in the message field. I've achieved that with this expression: `((\b\w+)[\.?!\s\"]*$)`. But it doesn't work with Elasticsearch. How I can modify this regex in order to work. Any ideas?

---

<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:** [April 19, 2019, 3:08pm UTC](https://discuss.elastic.co/t/regex-expression-ignore-all-characters-and-match-only-the-last-word-in-the-message-field/173514/2 "2019-04-19T15:08:12Z")

</div>

Closed on April 19, 2019, 3:08pm UTC

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