title: How to find which group is matched in NSRegularExpression
body: <p>I have a regex statement with multiple capture groups which are separated by | operator. How can I find out which capture group is matched? Only way I can think of -for this example- is counting the number of characters if something is matched.</p>
  
  <pre><code>var string = "1234567897"
  var pattern = "(^\\d{9}$)|(^\\d{10}$)|(^\\d{13}$)|(^[a-zA-Z]{2}\\d{9}[a-zA-Z]{2}$)"
  
  var myRegex = NSRegularExpression(pattern: pattern, options: nil, error: nil)!
  
  if let myMatch = myRegex.firstMatchInString(string, options: nil,
      range: NSRange(location: 0, length: string.utf16Count)) {
          println((string as NSString).substringWithRange(myMatch.rangeAtIndex(0)))
  
  }
  </code></pre>