我正在尝试使用正则表达式解析字符串。我有一个内容 text:text,我想从包含 text:text 的字符串中解析内容。 代码:
String lines=" from:cal_date_d type:string relationship:many_to_one sql_on:${fact_customer.dw_update_date} = ${cal_date_d.dw_update_date}";
Pattern p = Pattern.compile("(\"?[\\w ]*)\\:(\"?([\\w]*)\"?)");
Matcher m = p.matcher(lines);
while(m.find()) {
String Column_Data=m.group(0);
System.out.println("Regex: "+Column_Data);
}
输出:
from:cal_date_d
type:string
relationship:many_to_one
sql_on:
预期输出:
from:cal_date_d
type:string
relationship:many_to_one
sql_on:${fact_customer.dw_update_date} = ${cal_date_d.dw_update_date}
最佳答案
关于java - java中使用正则表达式解析字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41499776/