我有一串看起来像这样的数据,它在一行上。
<record xmlns:f="http://abc.com/">
<f:Table><f:Row><f:Cell>#1</f:Cell></f:Row><f:Row><f:Cell>Data 222</f:Cell></f:Row><f:Row> <f:Cell>Version: v3</f:Cell></f:Row><f:Row><f:Cell>Serial Number: 000000000</f:Cell></f:Row> <f:Row><f:Cell>Signature: 123</f:Cell></f:Row><f:Row><f:Cell>Issuer:</f:Cell></f:Row><f:Row> <f:Cell>C=EE,</f:Cell></f:Row><f:Row><f:Cell>ST=ABC,</f:Cell></f:Row><f:Row><f:Cell>L=avavv,</f:Cell></f:Row><f:Row><f:Cell><f:HexDump><f:Line seq=""0x0000"" hex=""09 09 4f 3d 5a 65 72 6f 54 75 72 6e 61 72 6f 75"">..O=ABC</f:Line><f:Line seq=""0x0010"" hex=""6e 64 20 4f c3 9c 2c"">nd OÇ.,</f:Line></f:HexDump></f:Cell></f:Row><f:Row><f:Cell>OU=abc,</f:Cell></f:Row><f:Row><f:Cell>CN=trtrtrtr,</f:Cell></f:Row><f:Row><f:Cell>E=null,</f:Cell></f:Row><f:Row><f:Cell>Create: 03/03/2010 14:58</f:Cell></f:Row><f:Row><f:Cell>Expire: 04/02/2010 14:58</f:Cell></f:Row><f:Row><f:Cell>Subject:</f:Cell></f:Row><f:Row><f:Cell>C=EE,</f:Cell></f:Row><f:Row><f:Cell>ST=SS,</f:Cell></f:Row><f:Row><f:Cell>L=Tartu,</f:Cell></f:Row><f:Row><f:Cell><f:HexDump><f:Line seq=""0x0000"" hex=""09 09 4f 3d 5a 65 72 6f 54 75 72 6e 61 72 6f 75"">..O=ZeroTurnarou</f:Line><f:Line seq=""0x0010"" hex=""6e 64 20 4f c3 9c 2c"">nd OÇ.,</f:Line></f:HexDump></f:Cell></f:Row><f:Row><f:Cell>OU=KKK,</f:Cell></f:Row></f:Table>
我的 Ruby 正则表达式如下所示:
<f:HexDump>[\s\S]*,<\/f:Line><\/f:HexDump>
因此,我试图删除<f:HexDump>
和<f:/HexDump>
标签之间的所有内容(包括标签),但将内容保留在两者之间。
问题是我的正则表达式正在选择直到第二个<f:/HexDump>
标签之间的所有内容。
<f:HexDump><f:Line seq=""0x0000"" hex=""09 09 4f 3d 5a 65 72 6f 54 75 72 6e 61 72 6f 75"">..O=ABC</f:Line><f:Line seq=""0x0010"" hex=""6e 64 20 4f c3 9c 2c"">nd OÇ.,</f:Line></f:HexDump></f:Cell></f:Row><f:Row><f:Cell>OU=abc,</f:Cell></f:Row><f:Row><f:Cell>CN=trtrtrtr,</f:Cell></f:Row><f:Row><f:Cell>E=null,</f:Cell></f:Row><f:Row><f:Cell>Create: 03/03/2010 14:58</f:Cell></f:Row><f:Row><f:Cell>Expire: 04/02/2010 14:58</f:Cell></f:Row><f:Row><f:Cell>Subject:</f:Cell></f:Row><f:Row><f:Cell>C=EE,</f:Cell></f:Row><f:Row><f:Cell>ST=SS,</f:Cell></f:Row><f:Row><f:Cell>L=Tartu,</f:Cell></f:Row><f:Row><f:Cell><f:HexDump><f:Line seq=""0x0000"" hex=""09 09 4f 3d 5a 65 72 6f 54 75 72 6e 61 72 6f 75"">..O=ZeroTurnarou</f:Line><f:Line seq=""0x0010"" hex=""6e 64 20 4f c3 9c 2c"">nd OÇ.,</f:Line></f:HexDump>
这可以使用 Ruby 正则表达式来完成吗?