java - 字符串正则表达式之间的字符串

标签 java regex soap

所以我有以下字符串:

    <GetMyeBaySellingResponse xmlns="urn:ebay:apis:eBLBaseComponents" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">


<Timestamp>2016-06-03T08:56:30.123Z</Timestamp>

<....>
<.....>
</GetMyeBaySellingResponse>

我想要一个正则表达式来提取 ..... 主要问题是

有时到达

<GetMyeBaySellingResponse xmlns="urn:ebay:apis:eBLBaseComponents">

所以我需要寻找 <GetMyeBaySellingResponse 开头的东西和第一个>作为前缀

所以我需要一个 (start with <GetMyeBaySellingResponse and end with the first >) and (end with <GetMyeBaySellingResponse/>) 的匹配器

最佳答案

使用以下正则表达式。

/<GetMyeBaySellingResponse[^>]*>(?:([^<]*)<GetMyeBaySellingResponse\/>)?/

组 1 将包含该字符串(如果有)。

<小时/>

针对重新表述的问题进行了更新。上面的表达式不适用于问题中更新的文本。尝试使用以下正则表达式来匹配 GetMyeBaySellingResponse 中的任何文本(包括任何 XML 元素)。

/<GetMyeBaySellingResponse[^>]*>(?:((?:(?!<\/GetMyeBaySellingResponse>)(?:.|\s))*)<\/GetMyeBaySellingResponse>)?/

关于java - 字符串正则表达式之间的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37614746/

相关文章:

html - 属性html之间没有空格的正则表达式

regex - 解析源代码中的注释和字符串

javascript - 使用 Javascript 访问 JSON 解析 SOAP 信封

java - Android:将简单的光标链接到 ListView

java - Android实现了一个带有两个clip textview的progressBar

javascript - 允许在正则表达式中使用减号

java - 使用 Java 在 XML 中设置嵌入字段的文本

serialization - 序列化 PHP SOAPClient 对象

java - 将 Java 项目导出为 .jar,包含 .java 源代码并保留外部库依赖项

java - JNI如何管理C++代码中的静态变量?