2016-02-19 Swift example of regex

Here's a quick-and-dirty copy-paste example of a regex in Swift 2.0. It pulls the width and height as integers from the string in the first line.

  var str = "codecType: 'avc1' dimensions: 640 x 360} extensions: {<CFBasicHash 0x128511ae0 [0x19f53cb68]>{type = immutable dict, count = 15"
  let regex = try! NSRegularExpression(pattern: "[0-9]{2,4} x [0-9]{2,4}", options: [])
  if let result = regex.firstMatchInString(str, options: [], range:  NSMakeRange(0, str.characters.count)) {
      let dimensionString = (str as NSString).substringWithRange(result.range)
      let dimensionArray = dimensionString.componentsSeparatedByString(" x ")
      let width = Int(dimensionArray[0])
      let height = Int(dimensionArray[1])
      // Now do something with the width and height integers
  }