如果用正侧表达式替换里面的数字?
<content img_url= " ">
<pageinfo1 page_id= "12 ">
<picture1 effect= " " width= "383 " x= "33 " y= "0 " />
<picture2 effect= " " width= "383 " x= "483 " y= "0 " />
</pageinfo1>
<pageinfo2 page_id= "12 ">
<picture1 effect= " " width= "383 " x= "33 " y= "0 " />
<picture2 effect= " " width= "383 " x= "483 " y= "0 " />
</pageinfo2>
</content>
如上面的xml
我想把 节点的数字去掉pageinfo1 pageinfo2 替换成 pageinfo
picture1 picture2 替换成picture
不带数字?如何写这个正侧?谢谢。
------解决方案--------------------假设上面这段xml是s
s.replaceAll( " <(\\w*)\\d{1} ", " <$1 ");
------解决方案--------------------String.replaceAll( "pageinfo[0-9]+ ", "pageinfo ");
String.replaceAll( "picture[0-9]+ ", "picture ");
------解决方案--------------------killme2008 的方法不错!学习了。
但是忽略了 </pageinfo1> ,写成下边这样就更完美了:)
s.replaceAll( "( <[/]?\\w*)\\d{1} ", "$1 ");