Standard C++ method for validating a URLs format?
Is there a easy standards-compliant way to check if a URL string is a valid format? Either through a specific URL-type class or maybe someone cou开发者_开发百科ld show me how to do a regex validation of it?
As others have answered, there is no URL parsing or validation code in the C++ Standard Library nor in STL. Neither is there regular expression parsing.
The first place to look for a solved problem is Boost! Boost.Regex should have you on your way. And this answer has a great URL regular expression.
Nope, there isn't one.
On windows, you could take a look at the IsValidURL() function
Is there a easy standards-compliant way to check if a URL string is a valid format?
There's nothing in the standard library.
You can use the Poco library: https://pocoproject.org/docs/Poco.URI.html
Here is my use of it as a URL validator:
bool validateUrl(std::string u){
try {
Poco::URI uri(u);
}
catch (Poco::SyntaxException &e){
return false;
}
return true;
}
精彩评论