# Painless compile error using regex pattern

**URL:** <https://discuss.elastic.co/t/painless-compile-error-using-regex-pattern/264623>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [February 17, 2021, 10:32pm UTC](https://discuss.elastic.co/t/painless-compile-error-using-regex-pattern/264623 "2021-02-17T22:32:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rodrigo\_Rabioglio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rodrigo_rabioglio/32/84077_2.png) [@Rodrigo\_Rabioglio](https://discuss.elastic.co/u/Rodrigo_Rabioglio)\
**Post date:** [February 17, 2021, 10:32pm UTC](https://discuss.elastic.co/t/painless-compile-error-using-regex-pattern/264623/1 "2021-02-17T22:32:30Z")

</div>

Hello,

I'm getting a compile error when using regex patterns inside a scripted field. I couldn't figure out why this error is happening though, since I'm pretty sure the script is right, based on the [docs](https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-regexes.html).

Here is the error:

```auto
    "root_cause": [
      {
       "type": "script_exception",
       "reason": "compile error",
       "script_stack": [
    "... ate'].value;\nPattern p = /SJC/;\n\n// lp =~ p \n\nlp",
    " ^---- HERE"
       ],
       "script": "def lp = doc['last_breadcrumbs_sorting_record.destination.license_plate'].value;\nPattern p = /SJC/;\n\n// lp =~ p \n\nlp",
       "lang": "painless",
       "position": {
    "offset": 93,
    "start": 68,
    "end": 116
       }
      }, 

```

And this is an example document:

```auto
    {
      "_id": "3268105",
      "last_breadcrumbs_sorting_record": {
       "destination": {
        "license_plate": "SJC20200623088"
       }
      },

```

Im using kibana's scripted field editor, running on v 7.8.1

Tks

---

<div class="post-metadata">

**Author:** ![stu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stu/32/75063_2.png) [@stu](https://discuss.elastic.co/u/stu)\
**Post date:** [February 18, 2021, 2:54pm UTC](https://discuss.elastic.co/t/painless-compile-error-using-regex-pattern/264623/2 "2021-02-18T14:54:12Z")

</div>

Hi Rodrigo,  
That looks right to me. Please post the section of the error below "position". It'll look like this:

```auto
    "position" : {
      "offset" : 103,
      "start" : 78,
      "end" : 122
    },
    "caused_by" : {
      "type" : "illegal_argument_exception",
      "reason" : "Error compiling regex: Unexpected internal error"
    }
  },

```

Also, if you can post the raw script directly, it'll be easier to debug without the escaped newlines.

---

<div class="post-metadata">

**Author:** ![Rodrigo\_Rabioglio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rodrigo_rabioglio/32/84077_2.png) [@Rodrigo\_Rabioglio](https://discuss.elastic.co/u/Rodrigo_Rabioglio)\
**Post date:** [February 18, 2021, 6:00pm UTC](https://discuss.elastic.co/t/painless-compile-error-using-regex-pattern/264623/3 "2021-02-18T18:00:09Z")

</div>

Hi @stu thanks for the response!

I've just checked the whole error stack and saw that regexes were not enabled 😕

```auto
"caused_by": {
     "type": "illegal_state_exception",
     "reason": "Regexes are disabled. Set [script.painless.regex.enabled] to [true] in elasticsearch.yaml to allow them. Be careful though, regexes break out of Painless's protection against deep recursion and long loops."
    }
   }

```

The stack was so long (and with a repeating pattern on 90% of the stack) that I didn't pay attention to the full description.

Tks

---

<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:** [March 18, 2021, 6:00pm UTC](https://discuss.elastic.co/t/painless-compile-error-using-regex-pattern/264623/4 "2021-03-18T18:00:56Z")

</div>

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