【发布时间】:2026-01-14 17:30:01
【问题描述】:
我想使用正则表达式捕获作为 web 服务调用的一部分收到的部分响应。这是我收到的回复,我有兴趣捕获 ContactMessageTransport 队列的状态。
正在发送队列的状态:
<pogo:Status>Started</pogo:Status>
和队列名在行:
<pogo:Name>ContactMessageTransport</pogo:Name>
我使用了<pogo:Name>ContactMessageTransport[\w\W]*Started<\/pogo:Status>,它也获取了我不感兴趣的其他队列的状态。我发现很难匹配几行。你能帮忙吗?
<getAllMessageQueueInfoResponse xmlns="http:abcd.com/MessageQueueAnalyticsAPI">
<return>
<Entry xmlns:pogo="http://example.com/com/integration/services/messagequeueanalyticsservice">
<pogo:AckCount>0</pogo:AckCount>
<pogo:DestinationID>0</pogo:DestinationID>
<pogo:ErrorCount>25</pogo:ErrorCount>
<pogo:ID>67</pogo:ID>
<pogo:Latest>2017-11-28T00:00:00-05:00</pogo:Latest>
<pogo:Name>ContactMessageTransport</pogo:Name>
<pogo:NotAckCount>0</pogo:NotAckCount>
<pogo:Oldest>2017-11-28T00:00:00-05:00</pogo:Oldest>
<pogo:RetryableErrorCount>31</pogo:RetryableErrorCount>
<pogo:SkippedCount>0</pogo:SkippedCount>
<pogo:Status>Started</pogo:Status>
<pogo:UnsentCount>212</pogo:UnsentCount>
</Entry>
<Entry xmlns:pogo="http://example.com/com/integration/services/messagequeueanalyticsservice">
<pogo:AckCount>0</pogo:AckCount>
<pogo:DestinationID>0</pogo:DestinationID>
<pogo:ErrorCount>0</pogo:ErrorCount>
<pogo:ID>65</pogo:ID>
<pogo:Latest>2018-03-17T00:00:00-04:00</pogo:Latest>
<pogo:Name>Email</pogo:Name>
<pogo:NotAckCount>0</pogo:NotAckCount>
<pogo:Oldest>2018-03-17T00:00:00-04:00</pogo:Oldest>
<pogo:RetryableErrorCount>4</pogo:RetryableErrorCount>
<pogo:SkippedCount>0</pogo:SkippedCount>
<pogo:Status>Started</pogo:Status>
<pogo:UnsentCount>0</pogo:UnsentCount>
</Entry>
【问题讨论】:
-
您最好使用 XML 解析器然后尝试对其进行正则表达式。话虽如此,如果您必须使用正则表达式,那么您在这里使用的是什么其他语言,python?
-
正则表达式是我唯一的选择。它的java
-
我可以帮助使用正则表达式,并且可以在 python 中获得一个简单的示例来处理文本,但我对 Java 不太了解。如果这有帮助,请告诉我,我会写一个答案。
-
谢谢狙击手。感谢您的帮助
标签: regex