Reputation: 19
I was trying to validate URL links using regex, but not all the links are being completely identified. Can you please help me out?
I want the links to follow the pattern:
http://www.abcdef.org/xyz/content.aspx?menu id=190&id=3214
Upvotes: 0
Views: 467
Reputation: 2285
Regex for url with port in Objective c
It works well if don't have port number.
-(BOOL) validateUrl: (NSString *) candidate {
NSString *urlRegEx = @"^(http|https|ftp)\://(([a-zA-Z0-9-.]+\.[a-zA-Z]{2,3})|([0-2]*\d*\d\.[0-2]*\d*\d\.[0-2]*\d*\d\.[0-2]*\d*\d))(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9-._\?\,\'/\+&%\$#\=~])*[^.\,)(\s]$";
NSPredicate *urlTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", urlRegEx];
return [urlTest evaluateWithObject:candidate];
}
Upvotes: 0
Reputation: 20394
Assuming you are looking for a regular expression to match urls with a specific pattern:
You can use something like this to match http://www.abcdef.org/xyz/content.aspx?menu id=190&id=3214
:
http://.*?/[a-zA-z]+/content.aspx\?menu id=\d+?&id=\d+
Upvotes: 1