1. Engineering
  2. Computer Science
  3. write a regular expression in java script that could recognize...

Question: write a regular expression in java script that could recognize...

Question details

Write a regular expression in java script that could recognize any web page address (URL).

Requirements:

1. "http://", or "https://", is optional, and one of them may appear once, or not.

2. there is no need for a web page address to have "www"

3. the top level domain must be one of the available domains: "com", "org", "net", or "edu"

4. at least one word (word = at least 2 characters) must be at the front of the top level domain name, and they must be separated by "."

For instance, "ab.com", "ab.cd.efg.com", or "https://ab.com", or "abc.org", etc., they are all valid, but "a.com" is not valid

5. After the top level domain name, there may be zero, one, or more subcategories specified. If there is one subcategory, then symbol "/" must be used to separate it with the top level domain name or other subcategories.

For instance, "ab.com/xyz", "abc.def.net/xyz/xxx", "abc.edu/aaa/bbb.html", etc., are all valid

6. a web page address may end with symbol "/". That is, "abc.com", "abc.com/", or "abc.com/xyz/" are all valid.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution