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