Regex for URL
/https?:\/\/[A-Za-z0-9][^\s]*[^\s.,;:!?)\]'"]/gi
Matches
Examples
Note
Stops at whitespace and leaves off trailing punctuation, so a URL at the end of a sentence doesn’t take the full stop. Parse candidates with the URL constructor to be sure.
Matches in the example
"https://example.com/docs?page=2#intro""http://localhost:8080"
Token by token
httpthe text “http”s?the character “s”, optionally:the character “:”\/the character “/”\/the character “/”[A-Za-z0-9]one of: “A” to “Z”, “a” to “z” or “0” to “9”[^\s]*any character except a whitespace character, zero or more times, as many as possible[^\s.,;:!?)\]'"]any character except a whitespace character, “.”, “,”, “;”, “:”, “!”, “?”, “)”, the character “]”, “'” or “"”
Other patterns
- Email address
- URL
- IPv4 address
- UUID
- Hex color
- Date (YYYY-MM-DD)
- Time (24-hour)
- US phone number
- Phone number (E.164)
- US ZIP code
- Credit card number
- URL slug
- Username
- Strong password
- HTML tag
- Semantic version
- MAC address
- JSON Web Token
- Hashtag
- @mention
- Number
- Leading and trailing whitespace
- Repeated word
- Blank lines
- Markdown link
- Quoted string
- Domain name
- File extension
- Base64
- Trailing comma