title: Regex capture group swift
body: <p>I have a regex search method in string:</p>
  
  <pre><code>extension String {
      func searchRegex (regex: String) -&gt; Array&lt;String&gt; {
          do {
              let regex = try NSRegularExpression(pattern: regex, options: NSRegularExpressionOptions(rawValue: 0))
              let nsstr = self as NSString
              let all = NSRange(location: 0, length: nsstr.length)
              var matches : Array&lt;String&gt; = Array&lt;String&gt;()
              regex.enumerateMatchesInString(self, options: NSMatchingOptions(rawValue: 0), range: all) {
                  (result : NSTextCheckingResult?, _, _) in
                  let theResult = nsstr.substringWithRange(result!.range)
                  matches.append(theResult)
              }
              return matches
          } catch {
              return Array&lt;String&gt;()
          }
      }
  }
  </code></pre>
  
  <p>It works good. But if i have a regular expression <code>product_title:\['(.*)'</code> it returns me <code>product_title:[\'Some title bla bla\'</code> but i only need the part <code>(.*)</code>.</p>
  
  <p>I'm new in swift, but in python this problem solved by using <code>groups()</code> function. How to use capture group in swift. Please give me example.</p>