Answer the question
In order to leave comments, you need to log in
How to compose a regular expression to check URL c++?
Hello everyone, I ran into such a problem, I have a string, let's denote it with string url; how can you check if it is a valid url with the specified connection protocol, and if there is no protocol, then continue it with the string, assuming that the protocol is http? And then how to select a domain from this line with a valid URL (if it is valid at all)? Thank you!
Answer the question
In order to leave comments, you need to log in
Here's a regular expression like this:
const regex = /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)[email protected])?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?$/i;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question