title: Swift - Getting only AlphaNumeric Characters from String
body: <p>I'm trying to create an internal function for the <code>String</code> class to get only AlphaNumeric characters and return a string. I'm running into a few errors with how to convert the matches back into a string using Regex. Can someone tell me how to fix the code or if there's an easier way?</p>
  
  <p>I want something like this</p>
  
  <pre><code>let testString = "_&lt;$abc$&gt;_"
  let alphaNumericString = testString.alphaNumeric() //abc
  </code></pre>
  
  <p>So far I have:</p>
  
  <pre><code>extension String {
      internal func alphaNumeric() -&gt; String {
          let regex = try? NSRegularExpression(pattern: "[^a-z0-9]", options: .caseInsensitive)
          let string = self as NSString
          let results = regex?.matches(in: self, options: [], range: NSRange(location: 0, length: string.length))
          let matches = results.map {
              String(self[Range($0.range, in: self)!])
          }
          return matches.join()
      }
  }
  </code></pre>