亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我只想在我的角色匹配后得到接下來的 5 個詞

我只想在我的角色匹配后得到接下來的 5 個詞

C#
函數式編程 2022-12-04 10:36:01
我Regex在 C# 中使用。我想在我的字符串匹配后得到接下來的 5 個單詞。Regex regex = new Regex("Born(.*){0,5}"); string result = regex.Match(UrlString).Value;首先,我需要找到“Born”這個詞。然后我需要在找到“Born”這個詞后得到接下來的 5 個詞。例子輸入:例子——莫迪出生在瓦德納加爾的一個古吉拉特語家庭,小時候幫助父親賣茶,后來經營自己的攤位。結果:到古吉拉特語家庭但我沒有得到想要的結果。
查看完整描述

2 回答

?
溫溫醬

TA貢獻1752條經驗 獲得超4個贊

Regex r = new Regex("Born (?<words>([^ ]+ ){5})");

string input = "asd Born asd asd asd asd asd asd asd asd asd asd Born qwe qwe qwe qwe qwe rtz rtz rtz";


foreach (Match m in r.Matches(input))

{

    Console.WriteLine(m.Groups["words"].Value);

}

解釋:


(?<words>xxxxxx) // is a group which can be accessed from Matches

[^ ] // All characters except space " "

+ // one or more times

([^ ]+ ) // characters followed by a space => A word

{5} // five words


查看完整回答
反對 回復 2022-12-04
?
狐的傳說

TA貢獻1804條經驗 獲得超3個贊

string result = UrlString.Substring(UrlString.IndexOf("Born"), 300);

使用正則表達式:

string result = Regex.Match(UrlString,@"Born(.){300}").ToString())


查看完整回答
反對 回復 2022-12-04
  • 2 回答
  • 0 關注
  • 102 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號