When I run the following code in a Playground, I get an invalid range as a result:
import Cocoa
var error: NSError?
var captureGroups: [String] = []
var input = "http://www.google.com"
var pattern = "(https?|ftp|file|gopher|mailto|news|nntp|telnet|wais)://[a-zA-Z0-9_@]+([.:][a-zA-Z0-9_@]+)*/?[a-zA-Z0-9_?,%#~&/\\-]+([:.][a-zA-Z0-9_?,%#~&/\\-]+)*"
var internalExpression = NSRegularExpression(pattern: pattern, options: .CaseInsensitive, error: &error)!
if let match = internalExpression.firstMatchInString(input, options: nil, range: NSMakeRange(0, count(input))) {
match.numberOfRanges // 4
match.rangeAtIndex(0) // (0, 21)
match.rangeAtIndex(1) // (0, 4)
match.rangeAtIndex(2) // (17, 3)
match.rangeAtIndex(3) // (9223372036854775807,0)
}
This code has worked for other regular expressions, it seems to be only this one that is giving it trouble. I am not a RegEx expert, so I am unsure as to how I should proceed.