0

I'm trying to modify the following string using System.Text.RegularExpressions.Regex in C#, and I need to replace /(integer)x(integer)/ with /. For example in url, I need to replace /1080x1080/ to /. How can I do this? I studied regex but I couldn't figure out how to do it.

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
1

2 Answers 2

2

You can match in following way :

/\d+x\d+/

Replace the matching with your replacing string.

In C#, you can use Regex Replace method in following way :

string output = Regex.Replace("your_string", @"/\d+x\d+/", "/");
Sign up to request clarification or add additional context in comments.

1 Comment

Oh it was much more simple than I thought... thanks a lot!
0

You can replace the string using Regex.Replace:

string url = "https://scontent-icn1-1.cdninstagram.com/t51.2885-15/1080x1080/22158936_1794137857546339_3682912105310191616_n.jpg";
url = Regex.Replace(url, @"/\d+x\d+/", "/");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.