V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
earnrepuNey
V2EX  ›  iDev

有没有 iOS 最强大的 URL 正则表达式?

  •  
  •   earnrepuNey · 2015-06-19 20:06:18 +08:00 · 4451 次点击
    这是一个创建于 3231 天前的主题,其中的信息可能已经有所发展或是发生改变。
    网上能找到的都是针对特定的 URL 格式。有没有能匹配最广的?像微信能识别 t.tt, google.gm 这样的,有没有一个开源的 URL 正则表达式?
    9 条回复    2015-07-03 15:28:33 +08:00
    janxin
        1
    janxin  
       2015-06-19 20:36:35 +08:00
    NSString *urlRegEx =
    @"(http|https)://((\\w)*|([0-9]*)|([-|_])*)+([\\.|/]((\\w)*|([0-9]*)|([-|_])*))+";
    这个应该就够了把?
    lululau
        2
    lululau  
       2015-06-19 20:40:44 +08:00
    ruby -ruri -e 'puts URI.regexp'
    zioc
        4
    zioc  
       2015-06-19 21:42:17 +08:00
    sdk自带的不行吗?不过看不到正则
    earnrepuNey
        5
    earnrepuNey  
    OP
       2015-06-24 09:18:14 +08:00
    @janxin t.tt 你试试
    earnrepuNey
        6
    earnrepuNey  
    OP
       2015-06-24 09:18:30 +08:00
    @lk09364 看过,不满足需求
    janxin
        7
    janxin  
       2015-06-24 10:48:25 +08:00
    @earnrepuNey 没有问题啊,你的意思是不是想匹配不包含http://和https://的url?
    janxin
        8
    janxin  
       2015-06-24 10:57:39 +08:00
    @earnrepuNey 稍微修改一下就可以了: [(http|https)://]?((\\w)*|([0-9]*)|([-|_])*)+([\\.|/]((\\w)*|([0-9]*)|([-|_])*))+
    earnrepuNey
        9
    earnrepuNey  
    OP
       2015-07-03 15:28:33 +08:00
    @janxin 谢谢你的耐心回复。我很好奇微信能够识别 t.tt google.gm 这样的网址。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3701 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 04:25 · PVG 12:25 · LAX 21:25 · JFK 00:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.