Last active
February 17, 2023 18:41
-
-
Save bsara/8313247 to your computer and use it in GitHub Desktop.
Regex: URLs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(f|ht)tp(s)?://([A-Za-z0-9-]+\.)+[A-Za-z0-9-]+(/[A-Za-z0-9- ./?%&=]*)? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This regular expression is used to match URLs that start with either "http", "https", "ftp", or "ftps". Here's a breakdown of the individual parts of the expression:
(f|ht)tp
: This part matches either "ftp" or "http" at the beginning of the URL. The parentheses indicate a group, and the vertical bar "|" indicates an "or" condition.(s)?
: This part matches the letter "s" optionally, indicating that the URL may start with either "http" or "https", or "ftp" or "ftps".://
: This part matches the colon and double slash that follow the protocol.([A-Za-z0-9-]+.)+
: This part matches the domain name, which consists of one or more groups of letters, numbers, and hyphens, followed by a period. The plus sign "+" indicates that the preceding group must occur one or more times.[A-Za-z0-9-]+
: This part matches the top-level domain, which consists of letters, numbers, and hyphens. It occurs only once.(/[A-Za-z0-9- ./?%&=])?
: This part matches the path and query string. The question mark "?" indicates an optional character, and the asterisk "" indicates that the preceding group can occur zero or more times. The path can contain letters, numbers, hyphens, spaces, periods, forward slashes, question marks, percent signs, and ampersands.So, this regular expression can match URLs such as "http://www.example.com/page", "https://www.example.com/page?id=123", "ftp://example.com", "ftps://example.com/page%20with%20spaces".