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 could show me how to do a regex validation of it?
Asked
Active
Viewed 7,797 times
4 Answers
5
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.
4
Is there a easy standards-compliant way to check if a URL string is a valid format?
There's nothing in the standard library.

sbi
- 219,715
- 46
- 258
- 445
4
Nope, there isn't one.
On windows, you could take a look at the IsValidURL() function

JasonV
- 586
- 6
- 13
-
Not cross platform, but a close enough answer for now. I guess the only cross platform solution is to use regex patterns. – Jake Wilson Jun 17 '10 at 17:24
3
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;
}

MatsB
- 91
- 1
- 6