Usage of String.range in Swift 3.0

后端 未结 2 655
醉酒成梦
醉酒成梦 2020-12-06 05:00
let us = \"http://example.com\"
let range = us.rangeOfString(\"(?<=://)[^.]+(?=.com)\", options:.RegularExpressionSearch)
if range != nil {
    let found = us.sub         


        
相关标签:
2条回答
  • 2020-12-06 05:30

    In swift 3.0 rangeOfString syntax changed like this.

    let us = "http://example.com"
    let range = us.range(of:"(?<=://)[^.]+(?=.com)", options:.regularExpression)
    if range != nil {
         let found = us.substring(with: range!)
         print("found: \(found)") // found: example
    }
    
    0 讨论(0)
  • 2020-12-06 05:31

    In latest swift 3.0 using Xcode 8 Beta 6 (latest updates to SDK):

    let us = "http://example.com"
    let range = us.range(of: "(?<=://)[^.]+(?=.com)", options: .regularExpression)
    if range != nil {
        let found = us.substring(with: range!)
        print("found: \(found)") // found: example
    }
    
    0 讨论(0)
提交回复
热议问题