# Create Scripted Field using substring before "."

**URL:** <https://discuss.elastic.co/t/create-scripted-field-using-substring-before/238096>\
**Category:** Kibana\
**Created:** [June 22, 2020, 1:45pm UTC](https://discuss.elastic.co/t/create-scripted-field-using-substring-before/238096 "2020-06-22T13:45:32Z")\
**Posts on this page:** 1\
**Showing post:** 10

<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:** [June 23, 2020, 11:19am UTC](https://discuss.elastic.co/t/create-scripted-field-using-substring-before/238096/10 "2020-06-23T11:19:30Z")

</div>

So it looks like the below should work.

```auto
String str = doc['name.keyword'].value;
if (str.contains(".")) {
    String[] result = /./.split(str);
    return result[0];
}
return str;

```

But it leads to the error below. So if you're going down this route you might need to make those changes or wait for someone else who might know an easier way.

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

```

---

_[View the full topic](https://discuss.elastic.co/t/create-scripted-field-using-substring-before/238096)._
