Hive replaces IP and port numbers in fields by regular expression

Scenes:

        There is a field in the table that stores one or more URL addresses. Now you need to replace the IP and port numbers in all URLs in the field with new IP and port numbers.

The original data is as shown below:

 Need to replace ftps://192.168.85.222:990 with   http://233.146.24.111:9001

Run SQL:

select
old_fj,
regexp_replace(old_fj,'ftps://(?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\:([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])','http://233.146.24.111:9001/buckets/jsscssmx')  as new_fj
FROM
表名

operation result:

 Summarize:

The most important thing is to identify the IP plus port in the data through regular expressions

The regular expression is as follows:

(?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\:([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])

Supongo que te gusta

Origin blog.csdn.net/weixin_42258633/article/details/131005580
Recomendado
Clasificación