我有以下公式

(Trig01:BAO)/(((Trig01:COUNT*86400)-Trig01:UPI-Trig01:SOS)*2000)


我想分割并获取仅在冒号之前的凝视值的输出,

最终输出需要为-

{ "BAO","COUNT","UPI","SOS" }


提前致谢,

最佳答案

您可以尝试使用以下正则表达式模式中的Positive Lookbehind来获取冒号后的所有字母数字字符

(?<=:)[^\W]+


Online demo

模式说明:

  (?<=                     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());
}

09-05 04:05