# Forward slashes not matching in regexp query

**URL:** <https://discuss.elastic.co/t/forward-slashes-not-matching-in-regexp-query/119283>\
**Category:** Elasticsearch\
**Created:** [February 9, 2018, 5:34pm UTC](https://discuss.elastic.co/t/forward-slashes-not-matching-in-regexp-query/119283 "2018-02-09T17:34:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simon\_Leighton](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@Simon\_Leighton](https://discuss.elastic.co/u/Simon_Leighton)\
**Post date:** [February 9, 2018, 5:34pm UTC](https://discuss.elastic.co/t/forward-slashes-not-matching-in-regexp-query/119283/1 "2018-02-09T17:34:38Z")

</div>

I've created a mapping and regexp query to search urls but these are failing when I add a forward slash to the regex query

"mappings":{  
"document":{  
"properties":{  
"url":{  
"type":"text",  
"analyzer":"keyword"  
}  
}  
}  
}

Urls:  
[www.test.com/section1/page1](http://www.test.com/section1/page1)  
[www.test.com/section1/page2](http://www.test.com/section1/page2)  
[www.test.com/section1/](http://www.test.com/section1/)

"query": {  
"regexp": {  
"content": {  
"value": "[www.test.com/.\*](http://www.test.com/.*)"  
}  
}  
}

I would expect all 3 results to be returned for the above urls that are indexed but I get no results returned.

searching without the / returns the correct results  
"query": {  
"regexp": {  
"content": {  
"value": "[www.test.com](http://www.test.com).\*"  
}  
}  
}

Any help would be appreciated.

Thanks,  
Simon

---

<div class="post-metadata">

**Author:** ![mkramer](https://avatars.discourse-cdn.com/v4/letter/m/6f9a4e/32.png) [@mkramer](https://discuss.elastic.co/u/mkramer)\
**Post date:** [February 9, 2018, 6:25pm UTC](https://discuss.elastic.co/t/forward-slashes-not-matching-in-regexp-query/119283/2 "2018-02-09T18:25:07Z")

</div>

I believe you need to escape the dot and forward slash characters where they represent characters and not classes or delimiters. Your regular expression should be: `www\.test\.com\/.*` Refer to [this page](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html) for more information regarding regular expressions in Elasticsearch.

---

<div class="post-metadata">

**Author:** ![Simon\_Leighton](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@Simon\_Leighton](https://discuss.elastic.co/u/Simon_Leighton)\
**Post date:** [February 9, 2018, 8:29pm UTC](https://discuss.elastic.co/t/forward-slashes-not-matching-in-regexp-query/119283/3 "2018-02-09T20:29:48Z")

</div>

I've tried it with these too but still no luck (double backslashes used as it was complaining about single escaping)

> ```
> www\\.test\\.com\\/.* 
> www\\.test\\.com/.*
> 
> ```

---

<div class="post-metadata">

**Author:** ![mkramer](https://avatars.discourse-cdn.com/v4/letter/m/6f9a4e/32.png) [@mkramer](https://discuss.elastic.co/u/mkramer)\
**Post date:** [February 9, 2018, 8:51pm UTC](https://discuss.elastic.co/t/forward-slashes-not-matching-in-regexp-query/119283/4 "2018-02-09T20:51:28Z")

</div>

Comparing your query to the example queries [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html), it appears to expect a field name in the position that you have denoted as "content". Does the regular expression match when you replace it with "url"?

---

<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 9, 2018, 8:51pm UTC](https://discuss.elastic.co/t/forward-slashes-not-matching-in-regexp-query/119283/5 "2018-03-09T20:51:45Z")

</div>

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