弹性搜索正则表达式从右边获取最后7位数字 [英] Elastic search regex to get last 7 digits from right

查看:811
本文介绍了弹性搜索正则表达式从右边获取最后7位数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个格式的数据索引676767 2343423 2344444 32494444.我需要一个正则表达式从右边的最后7位数字拼贴。 Ex输出:2494444.我们尝试过的模式[0-9] {7}不起作用。

解决方案

在ElasticSearch ,该模式是默认锚定。这意味着,您不能依赖部分匹配,您需要匹配整个字符串和捕获最后连续的7位数字



使用

 。*([0-9] {7})

其中




  • 。* - 将匹配除换行之外的任何0+字符(尽可能多),然后将回溯匹配...

  • ([0-9] {7}) - 放置到Capture组1中的7位数字。



如果在正则表达式模式中定义了捕获组,Sense插件将返回捕获的值,因此,不需要完成额外的提取工作(或组访问工作)。


I have data indexed in this format 676767 2343423 2344444 32494444. I need a regular expression to pattern anlayser last 7 digits from right. Ex output: 2494444. Pattern which we have tried [0-9]{7} which is not working.

解决方案

In ElasticSearch, the pattern is anchored by default. That means, you cannot rely on partial matches, you need to match the entire string and capture the last consecutive 7 digits.

Use

.*([0-9]{7})

where

  • .* - will match any 0+ chars other than newline (as many as possible) and then will backtrack to match...
  • ([0-9]{7}) - 7 digits placed into Capture group 1.

The Sense plug-in returns the captured value if a capturing group is defined in the regular expression pattern, so, no additional extraction work (or group accessing work) needs to be done.

这篇关于弹性搜索正则表达式从右边获取最后7位数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆