正则语法
每个语言的语法不一样,大致类似。
1.
常用正则
1.nginx匹配
([^\s]+) - ([.+])
select
'([^\\s]+) - (\\[.+\\])'
注释: \转义,这里加上sql转义是两个转义。 括号括起来是一个字符集 . 代表任意字符,+代表至少一次(*为任意次,?为最多一次)
2.字符串分割
SELECT split('%180%霖易%|%180%商城%|%霖易商城%','\\|');
|代表或,如果分割需要转义。
3.特殊字符替换
SELECT regexp_replace('(名字)。|得到的sssa》《?','\\(.*?\\)|[^(a-zA-Z0-9\\u2E80-\\u9FFF)]|[\\( \\)《》。,〈〉、⼂\\⼁]|\\s+|,|"|\'','') as contact_name
-- 得到的sssa
4.scala 匹配写法
val relation1_1: Regex = ".*(宝贝|亲爱).*".r
val relation1_2 = "^[老]?[爸|妈|爹|娘].*".r
val relation1_3 = "^(老婆|妻子|媳妇|老公|丈夫|儿子|女儿|老[头爷]子|丈母娘|丈人|婆婆|内人|内子|太太|夫人|外子|爱人).*".r
val relation2_1 = "^[大小二三四五六七八九十]?[哥兄弟姐妹伯叔姑婶舅姨].*".r
val relation2_2 = "^[爷奶].*".r
val relation2_3 = "^老[大二三四五六七八九十].*".r
val relation3_1 = ".*(先生|老板|老板娘|小姐|女士|总$|经理$).*".r
val relation4_1 = ".*(老师).*".r
val relation5_1 = ".*(同学).*".r
val relation6_1 = "^老.*".r
val relation7_1 = ".*(提额|大额|高额|白户|黑户|额度|面签|信用|消费|金融|融资|款|借|POS|套现).*".r
val relation7_2 = ".*(贷|中介).*".r
val relation7_3 = ".*(办|刷|养).*".r
val relation7_4 = ".*(代).*".r
def getRelationByName(name:String): Int ={
name match {
case relation1_1(_) => 1
case relation1_2() => 1
case relation1_3(_) => if (name.contains("的")) 0 else 1
case relation2_1() => 2
case relation2_2() => 2
case relation2_3() => 2
case relation3_1(_) => 3
case relation4_1(_) => 4
case relation5_1(_) => 5
case relation6_1() => 6
case relation7_1(_) => 7
case relation7_2(_) => if (name.contains("房")) 0 else 7
case relation7_3(_) => if (name.contains("卡")) 7 else 0
case relation7_4() => if (name.contains("办")) 7 else 0
case _ => 0
}
}