Remove port number in image url?

Ryden Choi

I try to get image url using regex, and my code is below.

string IMG_REX_PATTERN = @"<[Ii][Mm][Gg][^>]*src\s*=\s*[\""\']?(?<IMAGE_URL>[^""'>\s]*)[\""\']?[^>]*>"; 
Match match = Regex.Match(result[i]["N_Dext5EditorField"].ToString(), IMG_REX_PATTERN, RegexOptions.IgnoreCase); 
string src = string.Empty; 
  if (match.Length > 0) 
 { 
     //portalUrl = https://test.beta.co.kr
     string portalUrl = DevelopmentHelper.GetPortalUrl(); 
     src = match.Groups[1].Value.Replace(portalUrl, ""); 
} 
else 
{ 
    src = ""; 
}

But, sometimes src contains port number like this.

src = :443/dext5editordata/2017/12/20171228_191217524_37634.png

I want to get url like this(not included port number)

src = /dext5editordata/2017/12/20171228_191217524_37634.png

I thought easy way is portalUrl + ":443", but port number is sometimes diffrent.

How can I fix my code? Please help me.

Ryden Choi

based on your replies, I changed my code.

if (match.Length > 0) 
{ 
     //portalUrl = https://test.beta.co.kr
     string portalUrl = DevelopmentHelper.GetPortalUrl(); 
     string tempsrc = match.Groups[1].Value; 

     var uri = new UriBuilder(tempsrc);
     string targetUrl = uri.Uri.ToString();
     src = targetUrl .Replace(portalUrl, "");
} 
else 
{ 
    src = ""; 
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Chrome Print - remove URL from footer but keep page number?

From Dev

Single regexp to get page URL but exclude port number from a full URL

From Dev

Laravel: URL::to('/') port number for localhost not included in db seed files

From Dev

Remove image tag from HTML string using image url

From Dev

PHP Guzzle 5: Cannot handle URL with PORT number in it

From Dev

How to remove the :port number from the end of an IIS URL?

From Dev

how to remove port number from URL in apache tomcat if connector port is 8081

From Dev

Nginx remove port number :8080 in the url

From Dev

How to get Base URL with port number in codeigniter 3.0.3

From Dev

HTTPS url with port number not working on iOS

From Dev

Remove Page Number from URL with .htaccess

From Dev

forward the domain and remove the port number from the URL

From Dev

Validate URL with valid port number and query string

From Dev

How to get the port number from the URL using jQuery?

From Dev

Port number getting stripped out of URL

From Dev

Get URL and port number from view

From Dev

Regex optionally match port number in url

From Dev

How to remove a number from the end of an URL using .htaccess?

From Dev

Can URL contain colons to represent a value other than port number

From Dev

Retrieve the source code of a url using pycurl and a port number?

From Dev

Nginx remove port number :8080 in the url

From Dev

Android - Forming an URL object specifying a port number

From Dev

Generate random number and place it inside image URL

From Dev

Redirect traffic to a domain with a port number without showing the port number in the URL

From Dev

serenity bdd default url with spring boot random port number

From Dev

empty background-image:url("") remove

From Dev

Where is or where should be the folder following the port number in a url?

From Dev

How to connect url with port number in java with Jsoup?

From Dev

nmap or ping a url with embedded port number?

Related Related

  1. 1

    Chrome Print - remove URL from footer but keep page number?

  2. 2

    Single regexp to get page URL but exclude port number from a full URL

  3. 3

    Laravel: URL::to('/') port number for localhost not included in db seed files

  4. 4

    Remove image tag from HTML string using image url

  5. 5

    PHP Guzzle 5: Cannot handle URL with PORT number in it

  6. 6

    How to remove the :port number from the end of an IIS URL?

  7. 7

    how to remove port number from URL in apache tomcat if connector port is 8081

  8. 8

    Nginx remove port number :8080 in the url

  9. 9

    How to get Base URL with port number in codeigniter 3.0.3

  10. 10

    HTTPS url with port number not working on iOS

  11. 11

    Remove Page Number from URL with .htaccess

  12. 12

    forward the domain and remove the port number from the URL

  13. 13

    Validate URL with valid port number and query string

  14. 14

    How to get the port number from the URL using jQuery?

  15. 15

    Port number getting stripped out of URL

  16. 16

    Get URL and port number from view

  17. 17

    Regex optionally match port number in url

  18. 18

    How to remove a number from the end of an URL using .htaccess?

  19. 19

    Can URL contain colons to represent a value other than port number

  20. 20

    Retrieve the source code of a url using pycurl and a port number?

  21. 21

    Nginx remove port number :8080 in the url

  22. 22

    Android - Forming an URL object specifying a port number

  23. 23

    Generate random number and place it inside image URL

  24. 24

    Redirect traffic to a domain with a port number without showing the port number in the URL

  25. 25

    serenity bdd default url with spring boot random port number

  26. 26

    empty background-image:url("") remove

  27. 27

    Where is or where should be the folder following the port number in a url?

  28. 28

    How to connect url with port number in java with Jsoup?

  29. 29

    nmap or ping a url with embedded port number?

HotTag

Archive