簡體   English   中英

字符串之間的正則表達式表達式

[英]String between to strings regex expression

所以我有以下字符串:

    <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>)?/
(?:[\n]*(?:(?:<.+>)(.*)(?:<.+>)))\n*

https://regex101.com/r/vK4fY6/3

我認為這個簡單的代碼可以完成這項工作。

<GetMyeBaySellingResponse [\S\s]*<\/GetMyeBaySellingResponse>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM