如何在蜂巢中用空格替换字符串模式?

时间:2019-08-28 14:42:04

标签: sql hive hiveql

我的字符串为:

https://maps.googleapis.com/maps/api/staticmap?center=41.892532+-87.63811&zoom=11&scale=2&size=280x320&maptype=roadmap&format=png&visual_refresh=true%7C&markers=size:mid%7Ccolor:0x8000ff%7Clabel:1%7C2413+S+State+St++Chicago+IL+60616%7C&markers=size:mid%7Ccolor:0x8000ff%7Clabel:2%7C3000+N+Halsted+St++Chicago+IL+60657%7C&markers=size:mid%7Ccolor:0x8000ff%7Clabel:3%7C++++&key=AIzaSyBNEAQcC5niAEeiP3zkA_nuWGvtl0IOEs4

我想在结尾处用空白而不是单个'+'替换'++++'模式。在蜂巢中使用regexp_replace和translation函数进行了尝试,但是它也替换了所有出现的'+'。

2 个答案:

答案 0 :(得分:1)

使用

regexp_replace(string,'[+]{4}','')

模式'[+] {4}'表示+字符四次。

测试:

select regexp_replace('++markers=size:mid%7Ccolor:0x8000ff%7Clabel:3%7C++++&','[+]{4}','');

结果:

OK
++markers=size:mid%7Ccolor:0x8000ff%7Clabel:3%7C&

答案 1 :(得分:0)

您尝试过吗?

replace(string, '++++', '')

诚然,这将替换所有出现的'++++',但您的字符串只有其中之一。