首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

在线求解,该如何解决

2012-01-06 
在线求解Stringstrid fd,{}sname 45hd324,width sadf324,type hgf56 ,style asdf_234fd ,height 2

在线求解
String   str   =   "id= 'fd,{}   s '   name= '45hd   324 '       ,width= 'sadf324 '   ,     type= 'hgf56 ',   style= 'asdf_234fd ',   height= '234_324 ' ";


在Java中用一条正则表达式,拆分出
id= 'fd,{}   s '
name= '45hd   324 '
width= 'sadf324 '
type= 'hgf56 '
style= 'asdf_234fd '
height= '234_324 '

就是求出一个元素(str)的属性(id)和属性值( 'fd,{}   s '),属性和属性之间可以用 ", "或者 "   "(空格)搁开,属性值中可以有 ", "、 "{} "等符号.


[解决办法]
http://community.csdn.net/Expert/topic/5468/5468827.xml?temp=.980694
[解决办法]
regex = "\\w+= '[^= ']+ '|\\w+=[^=]+ "
=====
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(str);

while (matcher.find()) {
// Get the match result
String result = matcher.group();
System.out.println(result);
}

热点排行