# Custom pattern not working

**URL:** <https://discuss.elastic.co/t/custom-pattern-not-working/196722>\
**Category:** Logstash\
**Created:** [August 26, 2019, 7:14am UTC](https://discuss.elastic.co/t/custom-pattern-not-working/196722 "2019-08-26T07:14:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nee\_Defeng](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nee_defeng/32/45771_2.png) [@Nee\_Defeng](https://discuss.elastic.co/u/Nee_Defeng)\
**Post date:** [August 26, 2019, 7:14am UTC](https://discuss.elastic.co/t/custom-pattern-not-working/196722/1 "2019-08-26T07:14:03Z")

</div>

hi guys, I want to parse the value like 'ABC\_100', and I am trying to use the custom pattern as this: ALPHANUM %{WORD}\_%{NUMBER}

When I use the GROK pattern in the filter as %{ALPHANUM:alphanumber}, it is not parsed, but if I use '%{WORD}\_%{NUMBER}' directly in GROK filter, ABC\_100 can be parsed into WORD and NUMBER respectively.

My question is: can I define a custom pattern name to represent %{WORD}\_%{NUMBER}?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [August 26, 2019, 1:52pm UTC](https://discuss.elastic.co/t/custom-pattern-not-working/196722/2 "2019-08-26T13:52:18Z")

</div>

> [@Nee\_Defeng](#):
>
> if I use '%{WORD}\_%{NUMBER}' directly in GROK filter, ABC\_100 can be parsed into WORD and NUMBER respectively.

Really? I get a \_grokparsefailure from

```
input { generator { count => 1 lines => ['ABC_199'] } }
filter { grok { match => { "message" => "%{WORD}_%{NUMBER}" } } }
output { stdout { codec => rubydebug { metadata => false } } }

```

The problem is that WORD matches \b\w+\b, and \w matches letters, numbers, and underscore, so WORD consumes the entire message, leaving nothing for the \_ and NUMBER to match. If you replace \_ with = in both message and pattern it will match.

---

<div class="post-metadata">

**Author:** ![Nee\_Defeng](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nee_defeng/32/45771_2.png) [@Nee\_Defeng](https://discuss.elastic.co/u/Nee_Defeng)\
**Post date:** [August 26, 2019, 11:05pm UTC](https://discuss.elastic.co/t/custom-pattern-not-working/196722/3 "2019-08-26T23:05:53Z")

</div>

Yes, Badger, you are correct. I have test the 'MYCODE [a-zA-Z]+\_%{NUMBER}' in pattern and it is working. Thanks again.

---

<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 23, 2019, 11:09pm UTC](https://discuss.elastic.co/t/custom-pattern-not-working/196722/4 "2019-09-23T23:09:56Z")

</div>

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