Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I run the following statement to replace the characters of ".." to ".":

CREATE TABLE TableA AS
SELECT Column1,
REGEXP_REPLACE(Column2, "..", ".") AS NewColumn
FROM TableB;

The result of NewColumn became ".......", what's wrong with the REGEXP_REPLACE() function?

question from:https://stackoverflow.com/questions/65952959/replace-function-for-hivesql-regexp-replace-not-working-as-intended

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
971 views
Welcome To Ask or Share your Answers For Others

1 Answer

In addition to what @mck proposed, you can use quantifier for repeating patterns

REGEXP_REPLACE(Column2, "\.{2}", ".")

Or if you want to replace 2 or more dots with single one:

REGEXP_REPLACE(Column2, "\.{2,}", ".")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...