Home:ALL Converter>Regular expression for url in iPhone

Regular expression for url in iPhone

Ask Time:2012-09-14T14:27:34         Author:Subin Kurian

Json Formatter

I am using a regular expression to validate a website address. But it is not working because its format is not correct in iPhone. Its logic is almost correct. Can anyone rebuild this regular expression for me in iPhone ?

(?<http>(http:[/][/]|www.)([a-z]|[A-Z]|[0-9]|[/.]|[~])*)

Author:Subin Kurian,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/12419182/regular-expression-for-url-in-iphone
Paras Joshi :

use this bellow method\n\n- (BOOL) validateUrl: (NSString *) stringURL {\n NSString *urlRegEx =\n @\"(http|https)://((\\\\w)*|([0-9]*)|([-|_])*)+([\\\\.|/]((\\\\w)*|([0-9]*)|([-|_])*))+\";\n NSPredicate *urlTest = [NSPredicate predicateWithFormat:@\"SELF MATCHES %@\", urlRegEx]; \n return [urlTest evaluateWithObject:stringURL];\n}\n\n\nhope this help you...\n\n:)",
2012-09-14T07:27:27
Grzegorz Krukowski :

For anyone having problem with accepted answer regexpression here is a version I'm using:\n\n(https?)://(([\\\\w\\\\!\\\\@\\\\#\\\\$\\\\%\\\\^\\\\&\\\\*\\\\(\\\\)\\\\-\\\\+\\\\=\\\\(\\\\)\\\\[\\\\]\\\\{\\\\}\\\\?\\\\<\\\\>])*)+([\\\\.|/](([\\\\w\\\\!\\\\@\\\\#\\\\$\\\\%\\\\^\\\\&\\\\*\\\\(\\\\)\\\\-\\\\+\\\\=\\\\(\\\\)\\\\[\\\\]\\\\{\\\\}\\\\?\\\\<\\\\>])*))+\n\n\nThe problem with accepted answer regexp is that:\n\\w - already contains \"_\" and numbers\n\nit fails for URLs having \"-\" after first dot",
2015-08-06T10:44:25
Eran Goldin :

This will catch http / https / plain subdomain.domain.suffix links:\n(Based on the good answer by Grzegorz Krukowski)\n\n@\"((https?)://)?(([\\\\w\\\\!\\\\@\\\\#\\\\$\\\\%\\\\^\\\\&\\\\*\\\\(\\\\)\\\\-\\\\+\\\\=\\\\(\\\\)\\\\[\\\\]\\\\{\\\\}\\\\?\\\\<\\\\>])*)+([\\\\.|/](([\\\\w\\\\!\\\\@\\\\#\\\\$\\\\%\\\\^\\\\&\\\\*\\\\(\\\\)\\\\-\\\\+\\\\=\\\\(\\\\)\\\\[\\\\]\\\\{\\\\}\\\\?\\\\<\\\\>])+))+\"",
2016-01-13T15:38:12
Hiren :

Check out this one\n\nNSString *urlRegEx =\n@\"(http|https)://((\\\\w)*|([0-9]*)|([-|_])*)+([\\\\.|/]((\\\\w)*|([0-9]*)|([-|_])*))+\";\n",
2012-09-14T06:34:39
yy