# Is posible to set a text as optional in RegularExpresions?

**URL:** <https://discuss.elastic.co/t/is-posible-to-set-a-text-as-optional-in-regularexpresions/291114>\
**Category:** Logstash\
**Created:** [December 7, 2021, 12:09pm UTC](https://discuss.elastic.co/t/is-posible-to-set-a-text-as-optional-in-regularexpresions/291114 "2021-12-07T12:09:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rodri.gz](https://avatars.discourse-cdn.com/v4/letter/r/aca169/32.png) [@rodri.gz](https://discuss.elastic.co/u/rodri.gz)\
**Post date:** [December 7, 2021, 12:09pm UTC](https://discuss.elastic.co/t/is-posible-to-set-a-text-as-optional-in-regularexpresions/291114/1 "2021-12-07T12:09:57Z")

</div>

Hola!

Se puede poner textos como opcionales en regex?

these days im reciving some logs with this format:

```auto
[07/12/2021 09:59:33 [Id XXXXXXXXXXXXXXXX] Parameters send to YYYYYY:
	action1: AAAAAAAAAAAA
	action2: BBBBBBBBBBBBBBBB
	action3: DDDDDDDDDDDDDDDDD
	log : file.log

```

these fields ( action 1, action 2 and action 3 ) are optional, therefore they may or may not come and I would like to parse them with a single Regex.

i tried something like  
`.....(action1: %{WORD:Action1} )? (action2: %{WORD:Action2} )? (action3: %{WORD:Action3} )?......`

but it doesn´t appear to work.

is posible to set this text + fields as optional ?

thanks in advanced!

---

<div class="post-metadata">

**Author:** ![AquaX](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aquax/32/92006_2.png) [@AquaX](https://discuss.elastic.co/u/AquaX)\
**Post date:** [December 7, 2021, 2:43pm UTC](https://discuss.elastic.co/t/is-posible-to-set-a-text-as-optional-in-regularexpresions/291114/2 "2021-12-07T14:43:20Z")

</div>

Did you not just ask this question in this post?

> [@Is posible to have iptional field with regex as grok optionals fields?](https://discuss.elastic.co/t/is-posible-to-have-iptional-field-with-regex-as-grok-optionals-fields/290645):
>
> Hello! i want to know if a could set a field as optional in regular expresions as i do with grok for example: (%{DATA:Message})? Thank you!

---

<div class="post-metadata">

**Author:** ![rodri.gz](https://avatars.discourse-cdn.com/v4/letter/r/aca169/32.png) [@rodri.gz](https://discuss.elastic.co/u/rodri.gz)\
**Post date:** [December 9, 2021, 8:22am UTC](https://discuss.elastic.co/t/is-posible-to-set-a-text-as-optional-in-regularexpresions/291114/3 "2021-12-09T08:22:43Z")

</div>

Oh yes, i didn't find the other post, thank you!

---

<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 6, 2022, 8:23am UTC](https://discuss.elastic.co/t/is-posible-to-set-a-text-as-optional-in-regularexpresions/291114/4 "2022-01-06T08:23:15Z")

</div>

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