我以这种方式获得了不正确的数据。我需要使用正则表达式在点之前和点符号之后提取数据。
我正在使用正则表达式,但我无法获得准确的数据。
我有2个scenrios:
String tableHeading=null;
Matcher matcher = Pattern.compile("(\"(.*?)\".*?)\\.(\"(.*?)\".*?)").matcher(formulaData);
while (matcher.find())
{
String Column_Data=matcher.group(0);
String[] pieces = Column_Data.split("\\.");
tableHeading=pieces[0];
columnHeading=pieces[1];
System.out.println(tableHeading+ ": "+columnHeading);
}//while
答案 0 :(得分:1)
只需将正则表达式修改为:
Matcher matcher = Pattern.compile("(\"([^()]*?)\")\\.(\"?([$\\w ]*)\"?)").matcher(formulaData);
(
和)
不是预期的。
答案 1 :(得分:0)
您不需要string.split
只使用Matcher
功能,Pattern
类就足够了。
String formulaData="(100*(FILTER(\"Fact - Bookings\".\"$ Total Gross Bookings\" USING (\"Booking Date\".\"Year\" = VALUEOF(\"CUR_YEAR\"))) - FILTER(\"Fact - Bookings\".\"$ Total Gross Bookings\" USING \"Booking Date\".\"Year\" = VALUEOF(\"PREV_YEAR\") AND \"Booking Date\".\"Sortable Number\" <= VALUEOF(\"PRV_YEAR_TD\") ) ) / FILTER(\"Fact - Bookings\".\"$ Total Gross Bookings\" USING \"Booking Date\".\"Year\" = VALUEOF(\"PREV_YEAR\") AND \"Booking Date\".\"Sortable Number\" <= VALUEOF(\"PRV_YEAR_TD\") ) )";
Matcher matcher = Pattern.compile("(\"[^\"]*\")\\.(\".*?\")").matcher(formulaData);
while (matcher.find())
{
System.out.println(matcher.group(1)+ ": "+matcher.group(2));
}
<强>输出:强>
"Fact - Bookings": "$ Total Gross Bookings"
"Booking Date": "Year"
"Fact - Bookings": "$ Total Gross Bookings"
"Booking Date": "Year"
"Booking Date": "Sortable Number"
"Fact - Bookings": "$ Total Gross Bookings"
"Booking Date": "Year"
"Booking Date": "Sortable Number"