Regular Expression Matching -Java

后端 未结 6 1659
轻奢々
轻奢々 2021-01-23 20:48

I am taking input from a file in following format:

(int1,int2) (int3,int4)

Now I want to read int1, int2, int3 and int4 in my Java code. How ca

6条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-23 20:54

    To build on your own method, you can use a much simpler regex:

    String s = "(1,2) (3,4)";
    Pattern p = Pattern.compile("\\d+");
    Matcher m = p.matcher(s);
    while (m.find()) {
        System.out.println(m.group());
    }
    

提交回复
热议问题