I am trying to parse a String using Regular expression. I have a content text:text and I want to parse the content from a string which has text:text. Code:
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);
}
Ouput:
from:cal_date_d
type:string
relationship:many_to_one
sql_on:
Expected Output:
from:cal_date_d
type:string
relationship:many_to_one
sql_on:${fact_customer.dw_update_date} = ${cal_date_d.dw_update_date}
sql_onvalue. What is the syntax ofsql_on? Will it always have a close brace and an equals sign before the internal spaces? Willsql_onalways appear, and appear last? You need some other aspect of it like that to base this on, or adopt a different approach.