solr DIH:RegExTransformer [英] solr DIH: RegExTransformer

查看:54
本文介绍了solr DIH:RegExTransformer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我需要对下面的第三列应用转换:

Currently, I need to apply a transformation on bellow third column:

ACAC | 0 | 01
ACAC | 0 | 0101
ACAC | 0 | 0102
ACAC | 0 | 010201

我需要将 010201" 转换为 01/02/01".

I need to transform "010201" to "01/02/01".

所以首先我需要:

  1. 修剪所有结尾的 0 个字符
  2. 将每 2 个数字分开并添加 "/" 字符.
  1. trim all ending 0 characters
  2. split each 2 numbers and add "/" character.

这个转换的上下文在solr 数据导入处理程序转换器,但它在内部使用 java regex 库.

The context of this transformation is inside solr data import handler transformers, but it's using java regex library internally.

有没有办法得到它?

我试过使用这个正则表达式:

I've tried using this regex:

目前,我需要对下面的第三列应用转换:

Currently, I need to apply a transformation on bellow third column:

ACAC | 0 | 01
ACAC | 0 | 0101
ACAC | 0 | 0102
ACAC | 0 | 010201

我需要将 010201" 转换为 01/02/01".

I need to transform "010201" to "01/02/01".

所以首先我需要:

  1. 修剪所有结尾的 0 个字符
  2. 将每 2 个数字分开并添加 "/" 字符.
  1. trim all ending 0 characters
  2. split each 2 numbers and add "/" character.

这个转换的上下文在solr 数据导入处理程序转换器,但它在内部使用 java regex 库.

The context of this transformation is inside solr data import handler transformers, but it's using java regex library internally.

有没有办法得到它?

(\d[1-9]{1})

它象征着我:

01/04/01/

并且需要:

01/04/01

替换表达式为:

$&/

有什么想法吗?

推荐答案

可以使用

\d{2}(?=(?:\d{2})+$)

替换为 $0/,参见 正则表达式演示.

详情

  • \d{2} - 两位数
  • (?=(?:\d{2})+$) - 一种正向前瞻,确保在字符串末尾出现一个或多个双位数.立>
  • \d{2} - two digits
  • (?=(?:\d{2})+$) - a positive lookahead that makes sure there are one or more occurrences of double digits up to the end of string.

替换中的 $0 代表整个匹配.

The $0 in the replacement stands for the whole match.

RegExTransformer 代码,使用

In the RegExTransformer code, use

<field column="colname" regex="\d{2}(?=(?:\d{2})+$)" replaceWith="$0/" />

这篇关于solr DIH:RegExTransformer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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