# Painless script unable to recognize special chars in String

**URL:** <https://discuss.elastic.co/t/painless-script-unable-to-recognize-special-chars-in-string/160820>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [December 13, 2018, 9:59pm UTC](https://discuss.elastic.co/t/painless-script-unable-to-recognize-special-chars-in-string/160820 "2018-12-13T21:59:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vchang](https://avatars.discourse-cdn.com/v4/letter/v/7bcc69/32.png) [@vchang](https://discuss.elastic.co/u/vchang)\
**Post date:** [December 13, 2018, 9:59pm UTC](https://discuss.elastic.co/t/painless-script-unable-to-recognize-special-chars-in-string/160820/1 "2018-12-13T21:59:04Z")

</div>

Hi Everyone,

PLEASE HELP!!

Kibana 5.4

My team and I are trying to do a simple task: Given a string, extract a specific part of a URL. For example if my string is "GET path="/social/holiday-gift-guide/..." we want to always extract what is right after last slash of "social" and right before the slash before "guide". The use case is that "holiday-gift-guide" is just a place holder and will NOT always be the case. i.e gift-bag, christmas-tree, etc.

 ![36%20PM](https://us1.discourse-cdn.com/elastic/original/3X/5/7/573971111fbb8901f1b2c44664aae6643bac0205.png)

The following script has no errors. The assumption is that on line 8. indexOf("/social/") has special characters that proceed it which are =" . Because of this, I am not seeing expected behavior which is to return the fields I am interested in.

Can someone please give a detailed explanation on why this is happening? Not so sure that escaping the characters are going to work in this case.

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [December 20, 2018, 8:45pm UTC](https://discuss.elastic.co/t/painless-script-unable-to-recognize-special-chars-in-string/160820/2 "2018-12-20T20:45:40Z")

</div>

Please don't post images of text as they are hardly readable and not searchable.

Instead paste the text and format it with `</>` icon. Check the rendering with the preview window.

I recommend debugging your code using java, starting with a given value you expect to get from the message.keyword field, and testing the result with your code.

---

<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 17, 2019, 8:45pm UTC](https://discuss.elastic.co/t/painless-script-unable-to-recognize-special-chars-in-string/160820/3 "2019-01-17T20:45:40Z")

</div>

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