Your regex doesn’t seem correct. Try this regex:
/^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n?]+)/img
RegEx Demo
More Related Contents:
- How do I get the YouTube video ID from a URL?
- Detect URLs in text with JavaScript
- Regular expression for URL validation (in JavaScript)
- How to extract base URL from a string in JavaScript?
- How can I match on, but exclude a regex pattern?
- jQuery Youtube URL Validation with regex
- RegEx to match stuff between parentheses
- REGEX: Capture Filename from URL without file extension
- Extract parameter value from url using regular expressions
- Extract keyword from Google search in Javascript
- Split a string between special characters [closed]
- Not able to get Regular Expression in javascript
- Regex to replace multiple spaces with a single space
- Regex to match all instances not inside quotes
- How can I get the destination URL for the onbeforeunload event?
- Regular expression which matches a pattern, or is an empty string
- Template literal inside of the RegEx
- JavaScript regex pattern concatenate with variable
- Get query string parameters url values with jQuery / Javascript (querystring)
- JavaScript replace/regex
- Regular Expression for formatting numbers in JavaScript
- JavaScript regular expression exception (Invalid group)
- JSLint “insecure ^” in regular expression
- Javascript regex match fails on actual page, but regex tests work just fine
- Remove trailing numbers from string js regexp
- Replace keys in template string with object properties
- Javascript – regex – word boundary (\b) issue
- How to properly escape characters in regexp
- How to loop all the elements that match the regex?
- How to get base domain from the URL in JavaScript