需要匹配的字符串如下:
#VRML V2.0 utf8 # Generated by VCGLIB, (C)Copyright 1999-2001 VCG, IEI-CNR NavigationInfo { type [ "EXAMINE", "ANY" ] } DEF Box01 Transform { scale 1 1 1 translation 0 0 0 children [ Shape { geometry IndexedFaceSet { creaseAngle .5 solid FALSE coord Coordinate { point [ 948.701 665.378 288.971, 948.204 665.874 259.231, 948.699 671.327 289.469, 948.203 671.32 259.229 ] } color Color { color [ 0.690196 0.345098 0.101961, 0.690196 0.345098 0.101961, 0.690196 0.345098 0.101961, 0.690196 0.345098 0.101961 ] } coordIndex [ 9,13,3,-1, 3,1,9,-1, 16,18,22,-1, 22,20,16,-1, 0,11,19,-1, 19,4,0,-1 ] } appearance Appearance { material Material { ambientIntensity 0.2 diffuseColor 0.9 0.9 0.9 specularColor .1 .1 .1 shininess .5 } } } ] } DEF Box02 Transform { scale 1 1 1 translation 0 0 0 children [ Shape { geometry IndexedFaceSet { creaseAngle .5 solid FALSE coord Coordinate { point [ 948.701 665.378 288.971, 948.204 665.874 259.231, 948.699 671.327 289.469, 948.203 671.32 259.229 ] } color Color { color [ 0.690196 0.345098 0.101961, 0.690196 0.345098 0.101961, 0.690196 0.345098 0.101961, 0.690196 0.345098 0.101961 ] } coordIndex [ 9,13,3,-1, 3,1,9,-1, 16,18,22,-1, 22,20,16,-1, 0,11,19,-1, 19,4,0,-1 ] } appearance Appearance { material Material { ambientIntensity 0.2 diffuseColor 0.9 0.9 0.9 specularColor .1 .1 .1 shininess .5 } } } ] } DEF Box03 Transform { scale 1 1 1 translation 0 0 0 children [ Shape { geometry IndexedFaceSet { creaseAngle .5 solid FALSE coord Coordinate { point [ 948.701 665.378 288.971, 948.204 665.874 259.231, 948.699 671.327 289.469, 948.203 671.32 259.229 ] } color Color { color [ 0.690196 0.345098 0.101961, 0.690196 0.345098 0.101961, 0.690196 0.345098 0.101961, 0.690196 0.345098 0.101961 ] } coordIndex [ 9,13,3,-1, 3,1,9,-1, 16,18,22,-1, 22,20,16,-1, 0,11,19,-1, 19,4,0,-1 ] } appearance Appearance { material Material { ambientIntensity 0.2 diffuseColor 0.9 0.9 0.9 specularColor .1 .1 .1 shininess .5 } } } ] }
写一个正则表达式获取所有的 Transform节点和Transform节点中的全部内容
Transform {
scale 1 1 1
translation 0 0 0
children
[
.................
]
}
DEF[\s\S]+?(Transform[\s\S]+?)DEF
首先非常感谢你的指点,有的没有DEF Box02这种别名定义,直接Transform开头,如何修改下?
@E1ement: (Transform[\s\S]+?)(DEF|Transform)
@湖底的鱼: 谢谢
Transform {[\s\S]*?children[[\s\S]*?]\s*}(?=(\s*DEF|$)) 试试
谢谢