使用java

时间:2017-01-06 05:53:43

标签: java regex

我正在尝试使用正则表达式解析String。我有一个内容文本: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}

2 个答案:

答案 0 :(得分:2)

尝试这种模式

UI5

https://regex101.com/r/c0q4W0/2

答案 1 :(得分:0)

如果您有"key1:value1 key2:value2..."这样的字符串,那么您可以使用此正则表达式:

([^ ]*:[^ ]*)

相关问题