将配置单元函数转换为java-translate和regexp\u replace

lh80um4z  于 2021-06-03  发布在  Hadoop
关注(0)|答案(1)|浏览(336)

1) 如何将下面的配置单元部分转换为java map reduce?

translate(regexp_replace(colA,"(\\\\=)","\\\\equalto"),"\[\]\(\)\{\}\^\?\+\*\$","____________")

在regexp\u replace中,我替换all=,在outer translate中,我替换影响将来regexp\u replace解析的所有字符(如果我不替换这些字符,它们稍后会引发异常)。
2) 我是否必须使用replacechars(),如果是,那么如何使用?
示例字符串格式为: tag1=573 tag2=ABC 0nuif6d Saturn 0i899 AA 0 (WORD) LOWER 0 (WORD2) HH 0 BB 0 CC 1 LL 0 D 0 FF 0 AB 0 UPPER 0 (ONCOLD) UPPER 1 PART: Sold \= 88vb JJ number\= 0 String "String_here" ANDND JUJFNG fill EXTRA SUNSET: empty tag3=/Informational tag4=/Value tag5=Value1/Value2 tag6=/AB/Acs Sy/Api Afg Hold Cones/HHH+11: 4.3.2-4.3.4 tag6=11123 tag7=Hello World tag8=a-dfdAds\=\= tag9=Value3 tag.9=Space separated words \= 88 , cold 87 Goal Run\=2, LOT OF SPACE SEPARATED GARBAGE WORDS tag.a=0( tag.b=02 注:标记不是硬编码为标记。它们可以是任何英文单词,如序列号或网址 serial_no=hello world website.address=\SO.com=/question 哪里 serial_no 以及 website.address 是标签。

lhcgjxsq

lhcgjxsq1#

说明

此表达式将:
假设标记名不包含空格
假设标记名与它们各自的值之间用 = 两边都没有空白 = 符号,而不是由 \ 假设标记名与前面的字符串用空格隔开,同样,值也将与下一个标记名用空格隔开
捕获标记名称和值
将避免在嵌入字符串值侧的等号上拆分字符串 (\S*?)(?<!\\)=(\S*.*?)(?=\S*(?<!\\)=|\Z)
然后,您可以根据需要重新组装或进一步处理字符串的各个组件。

示例

现场演示
示例文本
来自您在评论中包含的示例文本。现在还不清楚是什么定义了一个标记或等号来分隔名称和值: serial_no=hello world website.address=\SO.com=/question tag1=573 tag2=ABC 0nuif6d Saturn 0i899 AA 0 (WORD) LOWER 0 (WORD2) HH 0 BB 0 CC 1 LL 0 D 0 FF 0 AB 0 UPPER 0 (ONCOLD) UPPER 1 PART: Sold \= 88vb JJ number\= 0 String "String_here" ANDND JUJFNG fill EXTRA SUNSET: empty tag3=/Informational tag4=/Value tag5=Value1/Value2 tag6=/AB/Acs Sy/Api Afg Hold Cones/HHH+11: 4.3.2-4.3.4 tag6=11123 tag7=Hello World tag8=a-dfdAds\=\= tag9=Value3 tag.9=Space separated words \= 88 , cold 87 Goal Run\=2, LOT OF SPACE SEPARATED GARBAGE WORDS tag.a=0( tag.b=02 样本代码

import java.util.regex.Pattern;
import java.util.regex.Matcher;
class Module1{
  public static void main(String[] asd){
  String sourcestring = "source string to match with pattern";
    Pattern re = Pattern.compile("(\\S*?)(?<!\\\\)=(\\S*.*?)(?=\\S*(?<!\\\\)=|\\Z)",Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);

  Matcher m = re.matcher(sourcestring);
  int mIdx = 0;
    while (m.find()){
      for( int groupIdx = 0; groupIdx < m.groupCount()+1; groupIdx++ ){
        System.out.println( "[" + mIdx + "][" + groupIdx + "] = " + m.group(groupIdx));
      }
      mIdx++;
    }
  }
}

比赛
组0将具有整个子字符串组1将具有名称字段组2将具有值字段

[0][0] = serial_no=hello world 
[0][1] = serial_no
[0][2] = hello world 

[1][0] = website.address=\SO.com=/question
[1][1] = website.address
[1][2] = \SO.com=/question

[2][0] = tag1=573 
[2][1] = tag1
[2][2] = 573 

[3][0] = tag2=ABC 0nuif6d Saturn 0i899 AA 0 (WORD) LOWER 0 (WORD2) HH 0 BB 0 CC 1 LL 0 D 0 FF 0 AB 0 UPPER 0 (ONCOLD) UPPER 1 PART: Sold \= 88vb JJ number\= 0 String "String_here" ANDND JUJFNG fill EXTRA SUNSET: empty 
[3][1] = tag2
[3][2] = ABC 0nuif6d Saturn 0i899 AA 0 (WORD) LOWER 0 (WORD2) HH 0 BB 0 CC 1 LL 0 D 0 FF 0 AB 0 UPPER 0 (ONCOLD) UPPER 1 PART: Sold \= 88vb JJ number\= 0 String "String_here" ANDND JUJFNG fill EXTRA SUNSET: empty 

[4][0] = tag3=/Informational 
[4][1] = tag3
[4][2] = /Informational 

[5][0] = tag4=/Value 
[5][1] = tag4
[5][2] = /Value 

[6][0] = tag5=Value1/Value2 
[6][1] = tag5
[6][2] = Value1/Value2 

[7][0] = tag6=/AB/Acs Sy/Api Afg Hold Cones/HHH+11: 4.3.2-4.3.4 
[7][1] = tag6
[7][2] = /AB/Acs Sy/Api Afg Hold Cones/HHH+11: 4.3.2-4.3.4 

[8][0] = tag6=11123 
[8][1] = tag6
[8][2] = 11123 

[9][0] = tag7=Hello World 
[9][1] = tag7
[9][2] = Hello World 

[10][0] = tag8=a-dfdAds\=\= 
[10][1] = tag8
[10][2] = a-dfdAds\=\= 

[11][0] = tag9=Value3 
[11][1] = tag9
[11][2] = Value3 

[12][0] = tag.9=Space separated words \= 88 , cold 87 Goal Run\=2, LOT OF SPACE SEPARATED GARBAGE WORDS 
[12][1] = tag.9
[12][2] = Space separated words \= 88 , cold 87 Goal Run\=2, LOT OF SPACE SEPARATED GARBAGE WORDS 

[13][0] = tag.a=0( 
[13][1] = tag.a
[13][2] = 0( 

[14][0] = tag.b=02
[14][1] = tag.b
[14][2] = 02

相关问题