title: Extracting a list of substrings from MongoDB using a Regular Expression
body: <p>I need to extract a part of a string that matches a regex and return it.</p>
  
  <p>I have a set of documents such as:</p>
  
  <pre><code>{"_id" :12121, "fileName" : "apple.doc"}, 
  {"_id" :12125, "fileName" : "rap.txt"},
  {"_id" :12126, "fileName" : "tap.pdf"}, 
  {"_id" :12126, "fileName" : "cricket.txt"}, 
  </code></pre>
  
  <p>I need to extract all file extensions and return <code>{".doc", ".txt", ".pdf"}</code>.</p>
  
  <p>I am trying to use the <code>$regex</code> operator to find the sub strings and aggregate on the results but am unable to extract the required part and pass it down the pipeline.</p>
  
  <p>I have tried something like this without success:</p>
  
  <pre><code>aggregate([
    { $match: { "name": { $regex: '/\.[0-9a-z]+$/i', "$options": "i" } } },
    { $group: { _id: null, tot: { $push: "$name" } } }
  ])
  </code></pre>