首页 文章

如何使用正则表达式java获取两个字符之间的数字?

提问于
浏览
0

I have the string as follows :

SUB8&20.000, - &succes&09/12 / 18SUB12&100.000, - &failed&07/12 / 18SUB16&40.000, - &succes&09/12/18

I want to get a string "8&20.000","16&40.000" 介于 SUB,-&succes 之间


I want to get succes data how to get the string using java regex ?

3 回答

  • 1

    使用这个正则表达式,

    SUB([^,]*),-&succes
    

    Java代码,

    public static void main(String[] args) {
        String s = "SUB8&20.000,-&succes&09/12/18SUB12&100.000,-&failed&07/12/18SUB16&40.000,-&succes&09/12/18";
        Pattern p = Pattern.compile("SUB([^,]*),-&succes");
        Matcher m = p.matcher(s);
        while (m.find()) {
            System.out.println(m.group(1));
        }
    }
    

    打印,

    8&20.000
    16&40.000
    

    Check here

  • 2

    您可以使用模式 SUB[^S]+&success[^S]+ 并在此之后选择所需的模式 .

    两场比赛将是 SUB8&20.000,-&succes&09/12/18SUB16&40.000,-&succes&09/12/18 .

    一旦你选择了,你就可以用 [0-9]+&[0-9.]+ 去除不需要的东西 .

  • 1

    我不知道我是否正确回答你的问题 . 但是这个正则表达式会给出你正在寻找的精确字符串 .

    (?<=SUB)([^,]*)(?=,-&succes)
    

    https://regex101.com/r/RLFXNf/1

相关问题