[英]VB.Net regex random string
我有正則表達式代碼,從TextBox1獲取2個字符串之間的字符串。
TextBox1看起來像這樣:
href="www.example.com/account/05798/john123">
href="www.example.com/account/4970/max16">
href="www.example.com/account/96577/killer007">
href="www.example.com/account/3077/hackerboy1337">
href="www.example.com/account/43210/king42">
因此,它將從href="www.example.com/account/4321/
到">
(用戶名)獲得價值
問題是,該怎么辦? 我的正則表達式代碼:
(?<="href=""www.example.com/account/RANDOM_STRING/")(.*?)(?="">)
我知道我可以用\\w{4}
替換RANDOM_STRING
,但有些ID是5位數。
或者另一種選擇是這樣做
Dim strOne As String = "www.example.com/account/43210/king42"
Dim strMain As String = Split(strOne, "/account/")(1)
Dim strSubOne As String = Split(strMain, "/")(0)
Dim strSubTwo As String = Split(strMain, "/")(1)
你需要一個否定的字符類[^/]
來匹配任何字符而不是/
。 所以,用[^/]*
替換RANDOM_STRING
。
此外,在正則表達式模式中,匹配.
,你需要逃避點 - \\.
。
因此,您的正則表達式可以固定為
(?<="href=""www\.example\.com/account/[^/]*/").*?(?="">)
但是,您可以使用捕獲組來使用更簡單的正則表達式:
"href=""www\.example\.com/account/[^/]*/"(.*?)"">
您需要的值是Match.Groups(1).Value
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.