Skip to main content
 首页 » 编程设计

c#之匹配 .html 之前和之后的文本的正则表达式/

2024年01月25日26lyhabc

用这个字符串

http://sfsdf.com/sdfsdf-sdfsdf/sdf-as.html

我需要获取sdf-as

有了这个

hellow-1/yo-sdf.html

我需要yo-sdf

请您参考如下方法:

这应该得到你想要的:

Regex re = new Regex(@"/([^/]*)\.html$"); 
Match match = re.Match("http://sfsdf.com/sdfsdf-sdfsdf/sdf-as.html"); 
Console.WriteLine(match.Groups[1].Value); //Or do whatever you want with the value 

这需要在文件顶部使用 using System.Text.RegularExpressions; 才能工作。