I need this regular expression:
(https?:\/\/(?:w{1,3}.)?[^\s]*?(?:\.[a-z]+)+)(?![^<]*?(?:<\/\w+>|\/?>))
to match this pattern http://localhost:3000 or any url that has a port number.
Link to rubular https://rubular.com/r/tkCOv181H2KJtU
There are a few things to note in the pattern.
You have to escape the dot to match it literally in this part (?:w{1,3}\.)?
If you add the dot to the character class [^\s.]*
you don't have to make it a non greedy quantifier.
You can omit the outer capturing group if you want the match only.
You could make the port part optional (?::\d+)?
to match it:
https?:\/\/(?:w{1,3}\.)?[^\s.]+(?:\.[a-z]+)*(?::\d+)?(?![^<]*(?:<\/\w+>|\/?>))
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments