在c#中使用正则表达式从字符串中获取pageUrl (randompage.html)
本文关键字:pageUrl randompage html 获取 正则表达式 字符串 | 更新日期: 2023-09-27 18:13:08
如何使用正则表达式从以下路径提取pageurl randompage.html ?
/明星/thisisapath/randompage.html
对于任何以.html
结尾的路径,这应该可以工作:
[^'/]+'.html$
示例:https://regex101.com/r/pauXBb/2
如果您希望它更通用,并接受任何文件扩展名,那么尝试:
[^'/]+'.[^.]+$
示例:https://regex101.com/r/pauXBb/3
string your = "/stars/thisisapath/randompage.html";
var match = Regex.Match(input, @"/: (.+?).html").Groups[1].Value;
match
将具有您的randompage
值。现在你可以像这样添加html:
match+="html"
试试这个(['w-'.]+'.)'w+
。它会找到像这样的字符串/stars/thisisapath/random.page-5.html
试试这个正则表达式([^/]*)$