我有这样的字符串:
1454974419:1234;1454974448:3255,2255,66789
我想通过在java中使用正则表达式来提取/分组这些值。
1234
3255
2255
66789
答案 0 :(得分:3)
你可以使用这个基于lookbehind和negation的正则表达式:
(?<=[:,])[^;,]+
<强>解体:强>
(?<=[:,]) # 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);