Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 配置单元查询,仅替换子字符串的第一个匹配项_Regex_String_Hive_Hiveql_Regexp Replace - Fatal编程技术网

Regex 配置单元查询,仅替换子字符串的第一个匹配项

Regex 配置单元查询,仅替换子字符串的第一个匹配项,regex,string,hive,hiveql,regexp-replace,Regex,String,Hive,Hiveql,Regexp Replace,我需要替换给定字符串中第一个出现的子字符串。 例如,如果字符串是“我的名字是亚当”,我想用“@”替换第一个“a” 所以我想要的输出是我的n@me是亚当吗? 在MySQL中,有一个函数regexp\u replace,它有一个可选参数occurrence,用于指定要替换的实例数。但不幸的是,该可选参数在配置单元函数中不存在。有什么建议吗 hive> select regexp_replace('My name is Adam','^(.*?)a','$1@'); OK My n@me is

我需要替换给定字符串中第一个出现的子字符串。
例如,如果字符串是
“我的名字是亚当”
,我想用
“@”
替换第一个
“a”
所以我想要的输出是我的n@me是亚当吗?
在MySQL中,有一个函数
regexp\u replace
,它有一个可选参数
occurrence
,用于指定要替换的实例数。但不幸的是,该可选参数在配置单元函数中不存在。有什么建议吗

hive> select regexp_replace('My name is Adam','^(.*?)a','$1@');
OK
My n@me is Adam
Time taken: 0.061 seconds, Fetched: 1 row(s)
模式
“^(.*a)”表示:

  ^ - the beginning of the string
.*? - any character (.) zero or more times (*) not greedy (?)
 () - remember group, we will refer it in the replacement string as $1
  a - 'a' character literally
$1 - group number one in the pattern (everything before 'a')
 @ - '@' character literally
替换字符串“$1@”
表示:

  ^ - the beginning of the string
.*? - any character (.) zero or more times (*) not greedy (?)
 () - remember group, we will refer it in the replacement string as $1
  a - 'a' character literally
$1 - group number one in the pattern (everything before 'a')
 @ - '@' character literally
您可以在此处调试regexp: