匹配多个单词
\b(State of Formation|Jurisdiction)\b:[\d\D]?([\d\D]?)
多个空格合一
String cleanValue = ((String) value).trim().replaceAll("\s{1,}", " ");
0宽断言
零宽断言,大多地方这样定义它,用于查找在某些内容(但并不包括这些内容)之前或之后的东西,也就是说它们像 \b ^ $ < > 这样的锚定作用,用于指定一个位置,这个位置应该满足一定的条件(即断言),因此它们也被称为零宽断言。我的理解是在一个限定位置的字符串之前或之后进行匹配查找。
举例:
[ INFO ] [2019-10-21 20:16:43,055] [kafka-concurr-31] c.c.w.O.b.e.QYYDL2EtlPlugin content:{"detail.json":{"comType":"Società a responsabilità limitata","regNumber":"01490030069","extactType":"config","name":"(main name)","regID":"RI","EUID":"ITRI.01490030069","regOffice":"Registro delle imprese, 10129 TORINO, RI Italy"},"otherData":{"policyId":"QYYDL2","uniqueKey":"QYYDL2_01490030069","url":"https://e-justice.europa.eu/searchBris.do","downloadTime":"2019-10-15 09:28:52"},"info.txt":{"criteriaId":"01490030069","extactType":"config","downloadUrl":"https://e-justice.europa.eu/searchBris.do","PolicyId":"QYYDL2","url":"https://e-justice.europa.eu/searchBris.do","downloadTime":"2019-10-15 09:28:53"}}
cat xxx | grep -Po “(?=“uniqueKey”).*(?=info)” | grep -Po "(?=“uniqueKey”).(?=url)"
解释: (?=“uniqueKey”).(?=info)
用于指定uniqueKey位置 和 info 位置之间的数据
grep 提取数据
-P : --perl-regexp PATTERN is a Perl regular expression [是perl的表达式]
-o :--only-matching show only the part of a line matching PATTERN[仅显示匹配到的部分数据]
grep -Po "(?=resultCode:).*(?=})"