title: How to filter out alphanumeric strings in Scala using regular expression
body: <p>I want to filter out alphanumeric and numeric words from my file. I'm working on Spark-Shell. These are the contents of my file sparktest.txt:</p>
  
  <blockquote>
    <p>This is 1 file not 54783. Would you l1ke this file to be Writt3n to
    HDFS?</p>
  </blockquote>
  
  <p>Defining the file for collection:</p>
  
  <pre><code>scala&gt; val myLines = sc.textFile("sparktest.txt")
  </code></pre>
  
  <p>Saving the line into an Array with words of length greater than 2:</p>
  
  <pre><code>scala&gt; val myWords = myLines.flatMap(x =&gt; x.split("\\W+")).filter(x =&gt; x.length &gt;2)
  </code></pre>
  
  <p>Defining a regular expression to use. I only want string that match "[A-Za-z]+":</p>
  
  <pre><code>scala&gt; val regexpr = "[A-Za-z]+".r
  </code></pre>
  
  <p>Attempting to filter out the alphanumeric and numeric strings:</p>
  
  <pre><code>scala&gt; val myOnlyWords = myWords.map(x =&gt; x).filter(x =&gt; regexpr(x).matches)
  &lt;console&gt;:27: error: scala.util.matching.Regex does not take parameters
         val myOnlyWords = myWords.map(x =&gt; x).filter(x =&gt; regexpr(x).matches)
  </code></pre>
  
  <p>This is where I'm stuck.
  I want the result to look like this:</p>
  
  <blockquote>
    <p>Array[String] = Array(This, file, not, Would, you, this, file, HDFS)</p>
  </blockquote>