# How to use regex with vega

**URL:** <https://discuss.elastic.co/t/how-to-use-regex-with-vega/285237>\
**Category:** Kibana\
**Tags:** vega\
**Created:** [September 27, 2021, 1:51pm UTC](https://discuss.elastic.co/t/how-to-use-regex-with-vega/285237 "2021-09-27T13:51:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![forst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forst/32/94565_2.png) [@forst](https://discuss.elastic.co/u/forst)\
**Post date:** [September 27, 2021, 1:51pm UTC](https://discuss.elastic.co/t/how-to-use-regex-with-vega/285237/1 "2021-09-27T13:51:19Z")

</div>

I am new to vega lite / vega.

I'm trying to write a regex query for a java log error as following with vega tree layout.  
A field 'message' contains :

> ```
> [Poolthread] com.xxxx.content.core-bundle com.xxxxx.content.model.impl.RegisterTypeInternal(3179)] The activate method has thrown an exception (com.xxxxx.content.model.exception.ModelException: ModelException: {Code}-LCC-REP-FCT-002, {Message}-Access denied)
> com.xxxx.content.model.exception.ModelException: ModelException: {Code}-LCC-REP-FCT-002, {Message}-Access denied
> at com.xxxxx.content.repository.utils.ExceptionUtil.getException(ExceptionUtil.java:52)
> at com.xxxxx.content.repository.utils.ExceptionUtil.getException(ExceptionUtil.java:171)
> 
> ```

i'm use this regex which gets an exception word before the character : (like as ModelException ) but i don't how use this regex in vega . i tested this regex on the site regex101, you can test it this url [[regex101: build, test, and debug regex](https://regex101.com/r/Cl07Fb/1)]([https://regex101](https://regex101) test)  
i would that regex return value of the first group 1 : ModelException .

> ```
> ([a-zA-Z0-9_]+)(?=:)
> 
> ```

But the regexp functions return only boolean values. This function is used with the split and replace function. I can't use to define group, find, matchers like in java programming. I just wanted it to return the value found . otherwise if you have examples of the regexp functioon with vega. i want to .

Thank for your help

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [September 27, 2021, 5:20pm UTC](https://discuss.elastic.co/t/how-to-use-regex-with-vega/285237/2 "2021-09-27T17:20:51Z")

</div>

If you are looking to replace a string using a regex pattern then you would use the [replace](https://vega.github.io/vega/docs/expressions/#replace) function and define the regex pattern there.

---

<div class="post-metadata">

**Author:** ![forst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forst/32/94565_2.png) [@forst](https://discuss.elastic.co/u/forst)\
**Post date:** [September 27, 2021, 5:38pm UTC](https://discuss.elastic.co/t/how-to-use-regex-with-vega/285237/3 "2021-09-27T17:38:18Z")

</div>

no I just wanted regex to return the match found as if I extract a word from the message

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [September 27, 2021, 6:53pm UTC](https://discuss.elastic.co/t/how-to-use-regex-with-vega/285237/4 "2021-09-27T18:53:56Z")

</div>

I would look for a way to do this via DSL query against the index. Don't believe Vega has this functionality.

---

<div class="post-metadata">

**Author:** ![forst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forst/32/94565_2.png) [@forst](https://discuss.elastic.co/u/forst)\
**Post date:** [September 27, 2021, 7:17pm UTC](https://discuss.elastic.co/t/how-to-use-regex-with-vega/285237/5 "2021-09-27T19:17:16Z")

</div>

I wanted to see if there is an alternative

---

<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 25, 2021, 7:18pm UTC](https://discuss.elastic.co/t/how-to-use-regex-with-vega/285237/6 "2021-10-25T19:18:08Z")

</div>

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