2 回答
TA贡献1828条经验 获得超6个赞
像这样的事情怎么样?本质上将 TIME_ID_CATEGORY 或 PAGE_IMPRESSION 匹配到组 1,并将其后的任何内容(即后缀)匹配为组 2。
(TIME_ID_CATEGORY|PAGE_IMPRESSION)(\w+)
然后只需将第 2 组的内容替换为空字符串即可。或者只是替换为 Group 1,这也将消除后缀(请参见下面的代码片段)。
示例代码片段:
public static void main(String args[]) throws Exception {
String line = "WITH dataTab0 AS (SELECT TO_CHAR(to_date(tab_0_0.times),'YYYYMMDD') AS TIME_ID_CATEGORYe93bc60a0041,tab_0_0.request_id AS PAGE_IMPRESSIONf6beefc154b44e4b FROM full_contents_2";
Pattern p = Pattern.compile("(TIME_ID_CATEGORY|PAGE_IMPRESSION)(\\w+)");
Matcher m = p.matcher(line);
if (m.find()) {
String output = m.replaceAll("$1");
System.out.println(output);
//WITH dataTab0 AS (SELECT TO_CHAR(to_date(tab_0_0.times),'YYYYMMDD') AS TIME_ID_CATEGORY,tab_0_0.request_id AS PAGE_IMPRESSION FROM full_contents_2
}
}
添加回答
举报