title: Extract multiple words using regexp_extract in PySpark
body: <p>I have a list which contains some words and I need to extract matching words from a text line, I found <a href="https://stackoverflow.com/questions/48869922/how-to-efficiently-check-if-a-list-of-words-is-contained-in-a-spark-dataframe">this</a>, but it only extracts one word.</p>
  <p><strong>keys file content</strong></p>
  <p>this is a keyword</p>
  <p><strong>part_description file content</strong></p>
  <p>32015   this is a keyword hello world</p>
  <p><strong>Code</strong></p>
  <pre class="lang-py prettyprint-override"><code>import pyspark.sql.functions as F
  
  keywords = sc.textFile('file:///home/description_search/keys') #1
  part_description =  sc.textFile('file:///description_search/part_description') #2
  keywords = keywords.map(lambda x: x.split(' ')) #3
  keywords = keywords.collect()[0] #4
  df = part_description.map(lambda r: Row(r)).toDF(['line']) #5
  df.withColumn('extracted_word', F.regexp_extract(df['line'],'|'.join(keywords), 0)).show() #6
  </code></pre>
  <p><strong>Outputs</strong></p>
  <pre><code>+--------------------+--------------+
  |                line|extracted_word|
  +--------------------+--------------+
  |32015   this is a...|          this|
  +--------------------+--------------+
  </code></pre>
  <p><strong>Expected output</strong></p>
  <pre><code>+--------------------+-----------------+
  |                line|   extracted_word|
  +--------------------+-----------------+
  |32015   this is a...|this,is,a,keyword|
  +--------------------+-----------------+
  </code></pre>
  <p>I want to</p>
  <ol>
  <li><p>return all matching keyword and their count</p>
  </li>
  <li><p>and if <code>step #4</code> is the most effecient way</p>
  </li>
  </ol>
  <p>Reproducible example:</p>
  <pre class="lang-py prettyprint-override"><code>keywords = ['this','is','a','keyword']
  l = [('32015 this is a keyword hello world'      , ),
  ('keyword this'      ,   ),
  ('32015 this is a keyword hello world 32015 this is a keyword hello world'      ,   ),
  ('keyword keyword'      ,   ),
  ('is a'      , )]
  
  columns = ['line']
  
  df=spark.createDataFrame(l, columns)
  </code></pre>