# Support for Anchoring in Elasticsearch Regex

**URL:** <https://discuss.elastic.co/t/support-for-anchoring-in-elasticsearch-regex/14925>\
**Category:** Elasticsearch\
**Created:** [December 18, 2013, 7:19am UTC](https://discuss.elastic.co/t/support-for-anchoring-in-elasticsearch-regex/14925 "2013-12-18T07:19:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vaidik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vaidik/32/1134_2.png) [@vaidik](https://discuss.elastic.co/u/vaidik)\
**Post date:** [December 18, 2013, 7:19am UTC](https://discuss.elastic.co/t/support-for-anchoring-in-elasticsearch-regex/14925/1 "2013-12-18T07:19:48Z")

</div>

Hi Folks,

I see that Elasticsearch supports Regex. But that is limited to Lucene's  
Regex Engine which does not support anchoring i.e. the entire string will  
always be anchored. This works as long as you have fixed regular  
expressions to run, but in cases where the regex query is taken from the  
user, this becomes very limiting.

Is there an alternative regex engine for Elasticsearch that at least  
supports $ and ^ for anchoring? Quick Google and Github search did not get  
me anything. If not, then is anybody doing something similar or have a work  
around? One possible solution that I can think of is converting user's  
entered regex to Lucene compatible regex. But that gets really complex to  
do correctly with all the grouping and alternation in regex.

I don't want the entire Perl regex kind of support. Just the anchoring bit  
is important. Has anybody tried to solve this problem before?

Thanks,  
Vaidik Kapoor  
vaidikkapoor.info

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CACWtv5%3DvoJ1B7K9CN3M0O9hvLTyV0cJVq3qiy%2BJiy0crTfPRjg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CACWtv5%3DvoJ1B7K9CN3M0O9hvLTyV0cJVq3qiy%2BJiy0crTfPRjg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Lee\_Gee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lee_gee/32/1217_2.png) [@Lee\_Gee](https://discuss.elastic.co/u/Lee_Gee)\
**Post date:** [July 29, 2014, 12:24pm UTC](https://discuss.elastic.co/t/support-for-anchoring-in-elasticsearch-regex/14925/2 "2014-07-29T12:24:49Z")

</div>

Lucene and Elastic Search both anchor regexp by default.

"Lucene’s patterns are always anchored. The pattern provided must match the  
entire string. "

—

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

On Wednesday, December 18, 2013 7:19:48 AM UTC, Vaidik Kapoor wrote:

> Hi Folks,
> 
> I see that Elasticsearch supports Regex. But that is limited to Lucene's  
> Regex Engine which does not support anchoring i.e. the entire string will  
> always be anchored. This works as long as you have fixed regular  
> expressions to run, but in cases where the regex query is taken from the  
> user, this becomes very limiting.
> 
> Is there an alternative regex engine for Elasticsearch that at least  
> supports $ and ^ for anchoring? Quick Google and Github search did not get  
> me anything. If not, then is anybody doing something similar or have a work  
> around? One possible solution that I can think of is converting user's  
> entered regex to Lucene compatible regex. But that gets really complex to  
> do correctly with all the grouping and alternation in regex.
> 
> I don't want the entire Perl regex kind of support. Just the anchoring bit  
> is important. Has anybody tried to solve this problem before?
> 
> Thanks,  
> Vaidik Kapoor  
> vaidikkapoor.info

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/27a0c79c-94bc-4878-b355-dd4895bc4135%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/27a0c79c-94bc-4878-b355-dd4895bc4135%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 6, 2017, 1:12am UTC](https://discuss.elastic.co/t/support-for-anchoring-in-elasticsearch-regex/14925/3 "2017-07-06T01:12:32Z")

</div>


