用于性能测试的 C Sharp 中 URL 的正则表达式

Regular Expression for URL in C Sharp for Performance Testing

我正在使用 Visual Studio 2012 - Web 性能测试工具。

在这里我有一个 Referer URL 像这样。 (这大约有 30 行,但我保持简短)

https://first URL/Second/Third/Fourth/five/SearchResults?json=%7B%22SalesInventoryID%22%3Anull%2C%22BundleInventoryID%22%3Anull%2C%22InventorySalesPriceID%22%3Anull%2C%22SiteType %22%3A8%2C%22SiteName%22%3A%22Desert%20Club%22%2C%22PointsMin%22%3A1%2C%22PointsMax%22%3A999999%2C%22RoomType%22%3Anull%2C%22PriceMin%22%3A1 %2C%22PriceMax%22%3A999999%2C%22SeasonType%22%3Anull%2C%22FrequencyType%22%3Anull%2C%22CheckInType%22%3Anull%2C%22WeekMin%22%3A1%2C%22WeekMax%22%3A52%2C %22RoomMin%22%3A%221%22%2C%22RoomMax%22%3A%22999999%22%2C%22TourID%22%3A2022154%2C%22TourLocationID%22%3A54%2C%22ListResults%22%3Anull%2C%22BundledResults %22%3Anull%2C%22TourParticipantInfo%22%3A%7B%22TourID%22%3A2022154%2C%22SiteID%22%3A1%2C%22SiteName%22%3Anull%2C%22PersonID%22%3A364182%2C%22FirstName%22 %3A%22Lynn%20A.%22%2C%22LastName%22%3A%22McDougald%22%2C%22City%22%3A%22Charlotte%22%2C%22State%22%3A%22-%22%2C%22ShortState %22%3A%22-%22%2C%22Country%22%3Anull%2C%22CountryID%22%3A840%2C%22OwnerNumber%22%3A%226017104%22%2C%22OwnerStatus%22%3Anull%2C

搜索结果之后,一切都在不断变化。

有人可以告诉我吗,如果我在“/fourth”之后需要什么,我该怎么做

就像我只需要这样 - https://first URL/Second/Third/Fourth/

我试过了:

https://first URL/Second/Third/Fourth/.*

https://first URL/Second/Third/Fourth/(.*)

没用。

要获取第四个 URL 之后的所有内容,请使用以下

https?:\/\/(?:[^\/]+\/){4}(.*)

然后使用捕获组 1 获取第四个 / 之后的所有文本。

您可以在这里进行测试:Regex101 Demo

编辑: 来自@Doqnach 的建议

基于@degant

的正则表达式

https:\/\/[^\/]+\/[^\/]+\/[^\/]+\/[^\/]+\/(.*)

捕获第四部分以外的所有内容。以及前面部分的动态内容,使其占用 "everything after the 4th section" 而不是为每个部分使用显式内容。

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