Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

saleh.hi.62

macrumors member
Original poster
Jul 25, 2011
95
0
hello guys,

i am trying to validate URL with this method:

Code:
- (BOOL) validateUrl: (NSString *) candidate {
	
	NSString *urlRegEx=
	@"((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)";
    
	NSPredicate *urlTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", urlRegEx]; 
    return [urlTest evaluateWithObject:candidate];
	
}

it does not function! i think problem is with Regular expression !
 
Because Objective-C doesn't have special syntax for writing regular expressions, but instead reuses the general string syntax, for every backslash in a regular expression you need to write two backslashes in the string.

You haven't done that, at least not in the character class at the end of the regex.
 
Because Objective-C doesn't have special syntax for writing regular expressions, but instead reuses the general string syntax, for every backslash in a regular expression you need to write two backslashes in the string.

You haven't done that, at least not in the character class at the end of the regex.
Code:
((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\\\\\))+[\w\d:#@%/;$()~_?\\+-=\\\\\\.&]*)

i am using this now according to what you said, but still it does not work!
 
Code:
((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\\\\\))+[\w\d:#@%/;$()~_?\\+-=\\\\\\.&]*)

i am using this now according to what you said, but still it does not work!

And what about \w and \d? These need to be \\w and \\d.

BTW I haven't actually been through your regex to see if it's actually correct for not. I'd just noticed these "syntax" errors.
 
And what about \w and \d? These need to be \\w and \\d.

BTW I haven't actually been through your regex to see if it's actually correct for not. I'd just noticed these "syntax" errors.

thank you my friend :) it already works :apple:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.