RegEx如何从嵌套的XML标签中检索值

时间:2019-01-23 01:34:35

标签: regex

我需要使用RegEx检索APPNAME和主机标签的值。

所需结果:TEST Web Server1,SERVERWEB1                  测试Web Server2,SERVERWEB2

非常感谢任何指导或指导:

<AppProperties>
      <Text>Test Web Server</Text>
    <ProgramGroup>TEST PROGRAM Group</ProgramGroup>
    <APPNAME>TEST Web Server1</APPNAME>
    <Hosts>
      <HostbyNetwork>
        <NetworkID>Default</NetworkID>
        <Host>SERVERWEB1</Host>
      </HostbyNetwork>
    </Hosts>
</AppProperties>

<AppProperties>
      <Text>Test Web Server</Text>
    <ProgramGroup>TEST PROGRAM Group</ProgramGroup>
    <APPNAME>TEST Web Server2</APPNAME>
    <Hosts>
      <HostbyNetwork>
        <NetworkID>Default</NetworkID>
        <Host>SERVERWEB2</Host>
      </HostbyNetwork>
    </Hosts>
</AppProperties>

1 个答案:

答案 0 :(得分:0)

以以下内容开头:

/
NAME>
([^<]+) # Match 1: anything but '<'
.+?
Host>
([^<]+) # Match 2: anything but '<'
/xs # Ignore pattern whitespace, dot matches newline

...?