我有以下公式
(Trig01:BAO)/(((Trig01:COUNT*86400)-Trig01:UPI-Trig01:SOS)*2000)
我想分割并获取仅在冒号之前的凝视值的输出,
最终输出需要为 -
{ "BAO","COUNT","UPI","SOS" }
提前致谢,
最佳答案
您可以尝试使用 Positive Lookbehind在下面的正则表达式模式中获取冒号后的所有字母数字字符
(?<=:)[^\W]+
模式解释:
(?<= look behind to see if there is:
: ':'
) end of look-behind
[^\W]+ any character except: non-word characters
(all but a-z, A-Z, 0-9, _) (1 or more times)
示例代码:
String str="(Trig01:BAO)/(((Trig01:COUNT*86400)-Trig01:UPI-Trig01:SOS)*2000)";
Pattern p=Pattern.compile("(?<=:)[^\\W]+");
Matcher m=p.matcher(str);
while(m.find()){
System.out.println(m.group());
}
关于java - 拆分和解析公式字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26863738/