求一个正则!!急!!

wj63558595 2012-04-30 09:28:41
br['35']='266,A 111,B 222'

我需要匹配出35,正则该怎么写啊
...全文
124 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
勇哥聊IT 2012-04-30
  • 打赏
  • 举报
回复
学习了
[Quote=引用 1 楼 的回复:]
String str = "br['35']='266,A 111,B 222'";
Pattern pattern = Pattern.compile("br\\['(\\d*)'\\]");
Matcher matcher = pattern.matcher(str);
while (matcher.find()) {
System.out.println(matcher.grou……
[/Quote]
若鱼1919 2012-04-30
  • 打赏
  • 举报
回复

str = "br['35']='266,A 111,B 222'";
str = str.replaceAll(".*?\\['(\\d+)'\\].*","$1");
System.out.println(str);
sdojqy1122 2012-04-30
  • 打赏
  • 举报
回复
哈哈,一刷新,发现一楼有答案了,现在我养成一个好习惯,发答案前先剪贴复制刷新。换个写法先。

String str = "br['35']='266,A 111,B 222'";
Pattern p = Pattern.compile("(?:br\\[')(\\d+)(?:'\\])");
Matcher m = p.matcher(str);
while(m.find()){
System.out.print(m.group(1));
};
chaozi_cssdns 2012-04-30
  • 打赏
  • 举报
回复
问题不是很清楚啊
MiceRice 2012-04-30
  • 打赏
  • 举报
回复
String str = "br['35']='266,A 111,B 222'";
Pattern pattern = Pattern.compile("br\\['(\\d*)'\\]");
Matcher matcher = pattern.matcher(str);
while (matcher.find()) {
System.out.println(matcher.group(1));
}

62,634

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧