所以我有以下字符串:
<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/