Skip to content
Advertisement

Very Simple Regex Question

I have a very simple regex question. Suppose I have 2 conditions:

  1. url =http://www.abc.com/cde/def
  2. url =https://www.abc.com/sadfl/dsaf

How can I extract the baseUrl using regex?

Sample output:

  1. http://www.abc.com
  2. https://www.abc.com

Advertisement

Answer

Like this:

JavaScript

However, you should use the URI class instead, like this:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement