# Logstash Regex

**URL:** <https://discuss.elastic.co/t/logstash-regex/273700>\
**Category:** Logstash\
**Created:** [May 21, 2021, 8:35pm UTC](https://discuss.elastic.co/t/logstash-regex/273700 "2021-05-21T20:35:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pmorenosi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pmorenosi/32/85248_2.png) [@pmorenosi](https://discuss.elastic.co/u/pmorenosi)\
**Post date:** [May 21, 2021, 8:35pm UTC](https://discuss.elastic.co/t/logstash-regex/273700/1 "2021-05-21T20:35:49Z")

</div>

Hello everybody,

in a logstash pipeline I am doing the following "if"

if [message] = ~ /^postfix.\*/anvil$/ {  
match =\> ["message", "% {POSTFIX\_ANVIL} $"]  
}

## LOG

May 11 05:49:37 smtp postfix / anvil [27651]: statistics: max cache size 3 at May 11 05:46:05

May 10 15:49:43 smtp postfix / oqmgr [6409]: 520D924F303: from = [jonathanvillal@example.com](mailto:jonathanvillal@example.com), size = 13516, nrcpt = 2 (queue active)

but this regular expression matches both lines since the email address matches " **anvil**", how can I make it match exactly with "postfix/anvil"

Thank you.

---

<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:** [May 21, 2021, 10:05pm UTC](https://discuss.elastic.co/t/logstash-regex/273700/2 "2021-05-21T22:05:36Z")

</div>

If you want to match anvil only when it is a word then include word boundaries in your pattern -- replace `anvil` with `\banvil\b`.

---

<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:** [June 20, 2021, 9:41pm UTC](https://discuss.elastic.co/t/logstash-regex/273700/4 "2021-06-20T21:41:57Z")

</div>

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