# Regex elasticsearch python API

**URL:** https://discuss.elastic.co/t/regex-elasticsearch-python-api/94383
**Category:** Elasticsearch
**Created:** [July 24, 2017, 6:57pm UTC](https://discuss.elastic.co/t/regex-elasticsearch-python-api/94383 "2017-07-24T18:57:08Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![diegoorellanaga](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@diegoorellanaga](https://discuss.elastic.co/u/diegoorellanaga)
#### Post date: [July 24, 2017, 6:57pm UTC](https://discuss.elastic.co/t/regex-elasticsearch-python-api/94383/1 "2017-07-24T18:57:08Z")

</div>

Hi,

I have been trying to make a regex ES search using the python API but I have not been able to. In my regex I'm trying to detect 8 consecutive digits: "._(^|[^\d])\d{8}($|[^\d])._" the app in [https://regex101.com/](https://regex101.com/) tells me this regex is ok. But when I use it on the ES python API I don't get what I should. I get no hits, but if I change d{8} for d{1} I get hits so I guess is a regex problem somehow. (and yes I have 8 consecutive digits names in that index)

```
> from elasticsearch import Elasticsearch
> es = Elasticsearch(['xxx.xxx.xxx:9200'])
> match = es.search(index="suricata-fileinfo-2017.07", doc_type='suricata-fileinfo', body={"query": {"regexp" : {"fileinfo_filename" : ".*(^|[^\d])\d{8}($|[^\d]).*"}}}, request_timeout=60)

```

Any idea what is wrong?

---

<div class="post-metadata">

### Author: ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)
#### Post date: [August 4, 2017, 11:04am UTC](https://discuss.elastic.co/t/regex-elasticsearch-python-api/94383/2 "2017-08-04T11:04:11Z")

</div>

Hi @diegoorellanaga,

I don't think this is Python specific. In the [regexp query docs](https://www.elastic.co/guide/en/elasticsearch/reference/master/query-dsl-regexp-query.html#regexp-syntax) I do not see that the `\d` character class is supported. Can you replace your regex with `".*(^|[^0-9])[0-9]{8}($|[^0-9]).*"` instead and retry?

Daniel

---

<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: [September 1, 2017, 11:04am UTC](https://discuss.elastic.co/t/regex-elasticsearch-python-api/94383/3 "2017-09-01T11:04:16Z")

</div>

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