问一个正则表达式

fwaction 2010-04-30 02:32:27
一个文件格式如下:
desc: MS001
os: AIX
state: Not Reachable
locked: no
....

都是以冒号分隔的 ,我想取到“Not Reachable"这个值,正则表达式该怎么写???
...全文
87 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
兔子-顾问 2010-04-30
  • 打赏
  • 举报
回复
(?m)(?<=state: ).+
fishrui 2010-04-30
  • 打赏
  • 举报
回复

//从文件中读出字符串
String str="desc: MS001,os: AIX,state:Not Reachable,locked: no";
Pattern p = Pattern.compile("state:(.*),");
Matcher m = p.matcher(str);
if(m.find()){
System.out.println(m.group(1));
}

aSysBang 2010-04-30
  • 打赏
  • 举报
回复
a:1
b:2

这种我一般用 Properties

fwaction 2010-04-30
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 gardner2010 的回复:]
字符串就可以处理啊
[/Quote]

我要正则表达式的写法!!!!
小贝壳666 2010-04-30
  • 打赏
  • 举报
回复
字符串就可以处理啊

62,614

社区成员

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

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