Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用正则表达式修改字符串_C#_Regex - Fatal编程技术网

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

我试图使用C#中的
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以获得良好的参考:哦,这比我想象的要简单得多。。。谢谢!哦,这比我想象的要简单得多。。。谢谢!