日期:2014-05-20  浏览次数:20627 次

在线求解
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);
}