C# 使用正则表达式修改字符串
我试图使用C#中的C# 使用正则表达式修改字符串,c#,regex,C#,Regex,我试图使用C#中的System.Text.RegularExpressions.Regex修改以下字符串,我需要将/(integer)x(integer)/替换为/。例如,在url中,我需要将/1080x1080/替换为/。我该怎么做?我学过正则表达式,但不知道怎么做 string url = "https://scontent-icn1-1.cdninstagram.com/t51.2885-15/1080x1080/22158936_1794137857546339_368291210531
System.Text.RegularExpressions.Regex
修改以下字符串,我需要将/(integer)x(integer)/
替换为/
。例如,在url
中,我需要将/1080x1080/
替换为/
。我该怎么做?我学过正则表达式,但不知道怎么做
string url = "https://scontent-icn1-1.cdninstagram.com/t51.2885-15/1080x1080/22158936_1794137857546339_3682912105310191616_n.jpg";
//The link is actually invalid because I modified it
您可以通过以下方式进行匹配:
/\d+x\d+/
string output = Regex.Replace("your_string", @"/\d+x\d+/", "/");
用替换字符串替换匹配项
在C#中,可以按以下方式使用:
/\d+x\d+/
string output = Regex.Replace("your_string", @"/\d+x\d+/", "/");
您可以通过以下方式进行匹配:
/\d+x\d+/
string output = Regex.Replace("your_string", @"/\d+x\d+/", "/");
用替换字符串替换匹配项
在C#中,可以按以下方式使用:
/\d+x\d+/
string output = Regex.Replace("your_string", @"/\d+x\d+/", "/");
可以使用以下方法替换字符串:
可以使用以下方法替换字符串:
参见msdn以获得良好的参考:参见msdn以获得良好的参考:哦,这比我想象的要简单得多。。。谢谢!哦,这比我想象的要简单得多。。。谢谢!