求一正则表达式取得其中的指定值,该怎么解决
求一正则表达式取得其中的指定值
有表达式(((indicator4-indicator3)>0)?"上升"+(label5-indicator3+label8):"下降"+(label7-label10-label12)),我想获得里面所有的以indicator、label开头的内容
indicator4、indicator3、label5、label8、label7、label10、label12等等
------解决方案--------------------
for example
有表达式(((indicator4-indicator3)>0)?"上升"+(label5-indicator3+label8):"下降"+(label7-label10-label12)),我想获得里面所有的以indicator、label开头的内容
indicator4、indicator3、label5、label8、label7、label10、label12等等
------解决方案--------------------
for example
- Java code
String s = "(((indicator4-indicator3)>0)?\"上升\"+(label5-indicator3+label8):\"下降\"+(label7-label10-label12))"; Pattern p = Pattern.compile("(?i)(indicator\\d+|label\\d+)"); Matcher m = p.matcher(s); while (m.find()) { System.out.println(m.group()); }
------解决方案--------------------
- Java code
public static void main(String[] args) { String str = "有表达式(((indicator4-indicator3)>0)?\"上升\"+(label5-indicator3+label8):\"下降\"+(label7-label10-label12)),我想获得里面所有的以indicator、label开头的内容"; Matcher m = Pattern.compile("(?<!\\w)(indicator|label)\\d+").matcher(str); while(m.find()){ System.out.println(m.group()); } }