redneon
20th April 2009, 10:20
I'm helping a friend of mine port a small application he's written from C# .NET to C++ QT and we've come across a little snag with the regular expressions.
In C# .NET we have a piece of code which looks similar to this:
private bool ValidURL(string url)
{
RegEx validURLRegex = new Regex("^(http|https)://[a-z0-9]+([-.]{1}[a-z0-9]+)*.[a-z]{2,5}(([0-9]{1,5})?/?.*)$");
if (validURLRegex.IsMatch(url))
return true;
return false;
}
I'm trying to convert this to use QRegExp (which I'm new to) and the code I come up with is this:
void SomeClass::ValidURL(QString url)
{
QRegExp validURLRegex("^(http|https)://[a-z0-9]+([-.]{1}[a-z0-9]+)*.[a-z]{2,5}(([0-9]{1,5})?/?.*)$");
if (validURLRegex.exactMatch(url))
return true;
return false;
}
This doesn't seem to work, however. I've tried various things, such as calling setMinimal(true) (not sure whether .NET uses greedy matching or not) and I've also tried setting the pattern syntax to all the available options, to no avail.
Any ideas?
In C# .NET we have a piece of code which looks similar to this:
private bool ValidURL(string url)
{
RegEx validURLRegex = new Regex("^(http|https)://[a-z0-9]+([-.]{1}[a-z0-9]+)*.[a-z]{2,5}(([0-9]{1,5})?/?.*)$");
if (validURLRegex.IsMatch(url))
return true;
return false;
}
I'm trying to convert this to use QRegExp (which I'm new to) and the code I come up with is this:
void SomeClass::ValidURL(QString url)
{
QRegExp validURLRegex("^(http|https)://[a-z0-9]+([-.]{1}[a-z0-9]+)*.[a-z]{2,5}(([0-9]{1,5})?/?.*)$");
if (validURLRegex.exactMatch(url))
return true;
return false;
}
This doesn't seem to work, however. I've tried various things, such as calling setMinimal(true) (not sure whether .NET uses greedy matching or not) and I've also tried setting the pattern syntax to all the available options, to no avail.
Any ideas?