# Scripted Field / Painless script fails upon slash for string match

**URL:** <https://discuss.elastic.co/t/scripted-field-painless-script-fails-upon-slash-for-string-match/211808>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [December 13, 2019, 2:53pm UTC](https://discuss.elastic.co/t/scripted-field-painless-script-fails-upon-slash-for-string-match/211808 "2019-12-13T14:53:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![codak7](https://avatars.discourse-cdn.com/v4/letter/c/c68b51/32.png) [@codak7](https://discuss.elastic.co/u/codak7)\
**Post date:** [December 13, 2019, 2:53pm UTC](https://discuss.elastic.co/t/scripted-field-painless-script-fails-upon-slash-for-string-match/211808/1 "2019-12-13T14:53:38Z")

</div>

Hi,

I am basically copy & pasting the first line of code under the section "Match a string and return that match" from this page: [https://www.elastic.co/blog/using-painless-kibana-scripted-fields](https://www.elastic.co/blog/using-painless-kibana-scripted-fields)

```
def m = /^([0-9]+)\..*$/.matcher(doc['clientip.keyword'].value);

```

 ![Kibana-01](https://us1.discourse-cdn.com/elastic/original/3X/0/0/005dac92603f2d52b5bbbaa781419dbf6792de45.png)  
But I always get an error when the code reaches the slash in the script.  
It also happens with other code samples from the page above, as soon as I reach a slash the script fails.

```
{
 "root_cause": [
  {
   "type": "script_exception",
   "reason": "compile error",
   "script_stack": [
    "def m = /^([0-9]+)\\..*$/.matcher( ...",
    " ^---- HERE"
   ],
   "script": "def m = /^([0-9]+)\\..*$/.matcher(doc['clientip.keyword'].value);",
   "lang": "painless"
  },
  {

```

 ![Kibana-02](https://us1.discourse-cdn.com/elastic/original/3X/9/3/9392a5fae0153112a45294911c67395ce98067c9.png)  
Any idea where I should look / what I should investigate to solve this?  
Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Brandon\_Kobel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_kobel/32/14829_2.png) [@Brandon\_Kobel](https://discuss.elastic.co/u/Brandon_Kobel)\
**Post date:** [December 16, 2019, 9:35pm UTC](https://discuss.elastic.co/t/scripted-field-painless-script-fails-upon-slash-for-string-match/211808/2 "2019-12-16T21:35:53Z")

</div>

@codak7, if you look down further in the exception, do you see the following:

> "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."

---

<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 13, 2020, 9:35pm UTC](https://discuss.elastic.co/t/scripted-field-painless-script-fails-upon-slash-for-string-match/211808/3 "2020-01-13T21:35:53Z")

</div>

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