Regular Expression Matching -Java

后端 未结 6 1664
轻奢々
轻奢々 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:58

    You could do something like:

    String str = "(1,2) (3,4)";
    Matcher m = Pattern.compile("\\((\\d+),(\\d+)\\) \\((\\d+),(\\d+)\\)").matcher(str);
    if (m.matches()) {
       System.out.println(m.group(1)); // number 1
       ...
    }
    

提交回复
热议问题