RegEx从Java中的下面的字符串中提取/分组冒号之后的所有值

时间:2016-02-09 18:32:22

标签: java regex

我有这样的字符串:

1454974419:1234;1454974448:3255,2255,66789

我想通过在java中使用正则表达式来提取/分组这些值。

1234

3255
2255
66789

2 个答案:

答案 0 :(得分:3)

你可以使用这个基于lookbehind和negation的正则表达式:

(?<=[:,])[^;,]+

RegEx Demo

<强>解体:

(?<=[:,])  # lookbehind to assert if previous char is : or ,
[^;,]+     # match 1 or more of anything that is not a ; or ,

答案 1 :(得分:-1)

试试这个

String yourString= "1454974419:1234;1454974448:3255,2255,66789";
          Pattern myPattern = Pattern.compile("[^a-zA-Z0-9]");
          Matcher myMatcher = myPattern.matcher(yourString);
            while(myMatcher.find())
            {
                String temp= myMatcher.group();
                yourString=yourString.replaceAll("\\"+temp, "");
            }
System.out.println(yourString);