# Regexp Not Evaluating as Expected

**URL:** <https://discuss.elastic.co/t/regexp-not-evaluating-as-expected/251954>\
**Category:** Beats\
**Tags:** winlogbeat\
**Created:** [October 13, 2020, 6:59pm UTC](https://discuss.elastic.co/t/regexp-not-evaluating-as-expected/251954 "2020-10-13T18:59:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eafrost.cissp](https://avatars.discourse-cdn.com/v4/letter/e/cab0a1/32.png) [@eafrost.cissp](https://discuss.elastic.co/u/eafrost.cissp)\
**Post date:** [October 13, 2020, 6:59pm UTC](https://discuss.elastic.co/t/regexp-not-evaluating-as-expected/251954/1 "2020-10-13T18:59:27Z")

</div>

I'm trying to drop events for which the winlog.event\_data.TargetUserName ends with `$` but keep the event when winlog.event\_data.TargetUserName has `$` not as the end character. Using the regular expressions 101 tester ([https://regex101.com](https://regex101.com)) the regex expression `\$$` does not match Te$t but does match Test$. However when I use this expression in my winlogbeat.yml file, it drops both events instead of keeping events with winlog.event\_data.TargetUserName equal to Te$t. See sample code below. Does winlogbeat not interpret the regex the same way as the tester does?

```auto
processors:
  - drop_event:
      when:
         regexp.winlog.event_data.TargetUserName: '\$$'

```

---

<div class="post-metadata">

**Author:** ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)\
**Post date:** [October 13, 2020, 10:18pm UTC](https://discuss.elastic.co/t/regexp-not-evaluating-as-expected/251954/2 "2020-10-13T22:18:32Z")

</div>

Your regular expression is correct so I was really confused. I added some debug to see what the raw string looks like before compiling the regex and it's `\$` so it's just doing a substring match to see if it contains any `$` literal.

```auto
Regex string raw: "\\$"
2020-10-13T18:09:27.981-0400	DEBUG	[conditions]	conditions/conditions.go:98	New condition regexp: map[message:<substring '$'>], map[]
2020-10-13T18:09:27.981-0400	DEBUG	[processors]	processors/processor.go:120	Generated new processors: add_tags=matches, condition=regexp: map[message:<substring '$'>], map[]

```

Then I remembered the config parsing does variable interpolation. 😅[https://www.elastic.co/guide/en/beats/filebeat/master/yaml-tips.html#dollar-sign-strings](https://www.elastic.co/guide/en/beats/filebeat/master/yaml-tips.html#dollar-sign-strings)

So you actually need

```auto
processors:
  - drop_event:
      when:
         regexp.winlog.event_data.TargetUserName: '\$$$'

```

---

<div class="post-metadata">

**Author:** ![mazoutte](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mazoutte/32/120188_2.png) [@mazoutte](https://discuss.elastic.co/u/mazoutte)\
**Post date:** [October 15, 2020, 6:56am UTC](https://discuss.elastic.co/t/regexp-not-evaluating-as-expected/251954/3 "2020-10-15T06:56:54Z")

</div>

Hello here,

I'm using this to filter out Computers :

`- regexp.winlog.event_data.TargetUserName: '.*\$'`

Cheers

---

<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:** [November 12, 2020, 8:57am UTC](https://discuss.elastic.co/t/regexp-not-evaluating-as-expected/251954/4 "2020-11-12T08:57:02Z")

</div>

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