# Grok pattern to account for #

**URL:** <https://discuss.elastic.co/t/grok-pattern-to-account-for/342616>\
**Category:** Logstash\
**Created:** [September 8, 2023, 2:50pm UTC](https://discuss.elastic.co/t/grok-pattern-to-account-for/342616 "2023-09-08T14:50:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jim\_Thunder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jim_thunder/32/45439_2.png) [@Jim\_Thunder](https://discuss.elastic.co/u/Jim_Thunder)\
**Post date:** [September 8, 2023, 2:50pm UTC](https://discuss.elastic.co/t/grok-pattern-to-account-for/342616/1 "2023-09-08T14:50:06Z")

</div>

I have log messages coming in and a few of them have one of three special characters: @, -, or #.

How can I get grok to ignore the hashtag without removing it from the new field? Below is the code snippet I'm using.

It works fine when it's just this:

> (?\<Tran\_ID\>[0-9A-Z@]{3,4})

But when I add the hasthtag, the rest becomes a comment:

> (?\<Tran\_ID\>[0-9A-Z@#-]{3,4})

---

<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:** [September 8, 2023, 4:46pm UTC](https://discuss.elastic.co/t/grok-pattern-to-account-for/342616/2 "2023-09-08T16:46:26Z")

</div>

Can you provide more detail? If I run

```
input { generator { count => 1 lines => ['{ "id": "The id is A1#9" }'] codec => json } }
output { stdout { codec => rubydebug { metadata => false } } }
filter { grok { match => { "id" => "(?<Tran_ID>[0-9A-Z@#-]{3,4})" } } }

```

then I get `"Tran_ID" => "A1#9"`.

---

<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:** [October 6, 2023, 4:47pm UTC](https://discuss.elastic.co/t/grok-pattern-to-account-for/342616/3 "2023-10-06T16:47:03Z")

</div>

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