hive 包含字符串,hive $符号
终极管理员 知识笔记 35阅读
一、背景
2.正则表达式匹配正则表达式中用到的特殊符号时需加\
3.正则表达式中各种扩号()[]{}作用
有的时候前端或者后端进行埋点日志会把json里面的数据再加上双引号或者特殊字符在落日志的时候组装的格式就不是正常的json数据了我们就需要将带有特殊字符的json数据解析成正常的json数据。
二、正则表达式基础介绍 1.正则表达式匹配引号匹配双引号用
匹配单引号’用’

如()[]{}/|-
匹配[用\[
匹配]用\]
匹配\用\\
匹配/用\/
匹配|用\|
匹配-用\-
匹配用\
匹配大写英文或小写英文或数字或下划线用\w或0-9a-zA-Z_

中括号[]表示匹配单个字符匹配中扩号里列出的任意一个字符
[dsa]//匹配d或s或a
小括号表示匹配字符串匹配小扩号里列出的所有字符构成的字符串
dsaff //仅能匹配dsaff
大括号{}表示匹配的次数放于()或[]之后
[dsa]{18}//匹配1-8次[dsa],如匹配d,dd,dddddddd(dsa){18}//匹配1-8次(dsa),如匹配dsa,dsadsadsadsadsadsadsadsa
4.常用匹配例子
例子匹配英语键盘上的任意非空字符
QRegExp re(^[\\w~!#$%^&*(){}:;<>?,.|\\[\\]\\-\\/\\\\]$); QString test(abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-~!#$%^&*()_[]{}|;:\\\/,.<>?); bool match re.exactMatch(test); //matchtrue
例子匹配任意合法表示的有理数
QRegExp reg(^(\\-(?!0(?!\\.))|\\(?!0(?!\\.)))?(0|[1-9]\\d*)(\\.\\d)?$); QString test(41424.4155346); bool match re.exactMatch(test); //matchtrue
例子匹配任意合法表示的非负有理数
QRegExp reg(^(\\(?!0(?!\\.)))?(0|[1-9]\\d*)(\\.\\d)?$); QString test(41424.4155346); bool match re.exactMatch(test); //matchtrue
例子匹配任意合法表示的正有理数
QRegExp reg(^(\\)?(0(?\\.)|[1-9]\\d*)(\\.\\d)?$); QString test(41424.4155346); bool match re.exactMatch(test); //matchtrue
例子匹配任意合法表示的整型数字
QRegExp reg(^(\\-(?!0)|\\(?!0))?(0|[1-9]\\d*)$); QString test(414246); bool match re.exactMatch(test); //matchtrue
例子匹配任意合法表示的非负整型数字
QRegExp reg(^(\\(?!0))?(0|[1-9]\\d*)$); QString test(414246); bool match re.exactMatch(test); //matchtrue
例子匹配任意合法表示的正整型数字
QRegExp reg(^(\\)?([1-9]\\d*)$); QString test(414246); bool match re.exactMatch(test); //matchtrue
例子匹配任意合法表示的密码
QRegExp reg(^[\\w~!#$%^&*(){}:;<>?,.|\\[\\]\\-\\/\\\\]$); if (!reg.exactMatch(value.data())) { message_ QObject::tr(The password can only contanin numbers, English characters or special characters ) .toStdString(); return false; } return true;
例子匹配任意合法表示的密码
QRegExp reg(^[\\w~!#$%^&*(){}:;<>?,.|\\[\\]\\-\\/\\\\]$); if (!reg.exactMatch(value.data())) { message_ QObject::tr(The password can only contanin numbers, English characters or special characters ) .toStdString(); return false; } return true;
三、带有特殊字符的json {event:eventDiagnose,extra:{url: 四、去除特殊字符不同的函数解析正则表达式的方法和功能不太一样regexp_replace会比translate更完善一些 insert overwrite table wedw_dw.chdisease_gpt_opt_log_dfselect id ,trace_id ,per_user_type ,oper_user_id ,oper_user_name,oper_type ,oper_module ,data_owner ,oper_data_id ,regexp_replace(regexp_replace(translate(translate(translate(translate(log_desc,\n,),\r, ),\t, ),\\,),(\\\\{),\\{),(\\}\\),\\}) as log_desc ,gmt_created ,regexp_replace(regexp_replace(translate(translate(translate(translate(oper_result,\n,),\r, ),\t, ),\\,),(\\\\{),\\{),(\\}\\),\\}) as oper_result ,is_deleted from wedw_ods.chdisease_gpt_opt_log_df;
正常的json字符串
{event:eventPrescription,extra:{url: -->zdbm:E11.501I79.2*,zdmc:2u578bu7cd6u5c3fu75c5u6027u5468u56f4u8840u7ba1u75c5u53d8}],[{zdbm:E11.401G63.2*,zdmc:2u578bu7cd6u5c3fu75c5u6027u5468u56f4u795eu7ecfu75c5},{zdbm:E78.500,zdmc:u9ad8u8102u8840u75c7}]],token:089b85839db94a80a6c4f09352f97104,appKey:4QG1dS38sdBQyhSe,diagnoses:[{diagnosisCode:E11.501I79.2*,diagnosisName:2u578bu7cd6u5c3fu75c5u6027u5468u56f4u8840u7ba1u75c5u53d8,diagnosisType:1},{diagnosisCode:E11.401G63.2*,diagnosisName:2u578bu7cd6u5c3fu75c5u6027u5468u56f4u795eu7ecfu75c5,diagnosisType:2},{diagnosisCode:E78.500,diagnosisName:u9ad8u8102u8840u75c7,diagnosisType:2}],suspensionBallDialogIndex:1,medicines:[{pscId:WG202310220538601,commonName:u745eu8212u4f10u4ed6u6c40u9499u7247,productName:u745eu8212u4f10u4ed6u6c40u9499u7247},{pscId:WG202310220538601,commonName:u4f9du5e15u53f8u4ed6u7247,productName:u5510u6797},{pscId:WG202310220538601,commonName:u80f0u6fc0u80bdu539fu9176u80a0u6eb6u7247,productName:u6021u5f00}]},source:yh,userId:120224196302163822,visitCode:MZ0949231022475927}
标签: