# Logstash regex expression in conf xpath

**URL:** <https://discuss.elastic.co/t/logstash-regex-expression-in-conf-xpath/349252>\
**Category:** Logstash\
**Created:** [December 13, 2023, 11:29am UTC](https://discuss.elastic.co/t/logstash-regex-expression-in-conf-xpath/349252 "2023-12-13T11:29:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![d.silwon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/d.silwon/32/65853_2.png) [@d.silwon](https://discuss.elastic.co/u/d.silwon)\
**Post date:** [December 13, 2023, 11:29am UTC](https://discuss.elastic.co/t/logstash-regex-expression-in-conf-xpath/349252/1 "2023-12-13T11:29:08Z")

</div>

Dears,

Can we use regex expression in logstash configuration in case of filter and xpath?

There is right now such to conditions:

```auto
...
filter {
  if "xmlapps" in [tags] {
  xml {
    source => "message"
    store_xml => false
    force_array => false
    xpath => [
      "/log//re/im/field[@id='0']/@value", "app.rec",
      "/log//se/im/field[@id='0']/@value", "app.rec"
    ]
  }
  }
...

```

Is there any way to use regex expression in one line instead of two separate lines?  
If yes please advise me how to do it. Thanks a lot.

Best Regards,  
Dan

---

<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:** [December 13, 2023, 5:32pm UTC](https://discuss.elastic.co/t/logstash-regex-expression-in-conf-xpath/349252/2 "2023-12-13T17:32:57Z")

</div>

xpath does not directly support regexes, so you cannot do something compact like "/log//(re|se)/...".

You may be able to do something using Xpath [functions](https://www.w3schools.com/xml/xsl_functions.asp), but creating an expression using something like starts\_with or starts\_with is probably not going to help anyone.

---

<div class="post-metadata">

**Author:** ![d.silwon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/d.silwon/32/65853_2.png) [@d.silwon](https://discuss.elastic.co/u/d.silwon)\
**Post date:** [December 13, 2023, 5:48pm UTC](https://discuss.elastic.co/t/logstash-regex-expression-in-conf-xpath/349252/3 "2023-12-13T17:48:31Z")

</div>

thanks a lot for your answer

---

<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:** [January 10, 2024, 5:48pm UTC](https://discuss.elastic.co/t/logstash-regex-expression-in-conf-xpath/349252/4 "2024-01-10T17:48:34Z")

</div>

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