title: R gsub to extract emails from text
body: <p>I have a variable <code>a</code> created by <code>readLines</code> of a file which contains some emails. I already filtered only those rows whith the @ symbol, and now am struggling to grab the emails. The text in my variable looks like this:</p>
  
  <pre><code>&gt; dput(a[1:5])
  c("buenas tardes. excelente. por favor a: Saolonm@hotmail.com", 
  "26.leonard@gmail.com ", "Aprecio tu aporte , mi correo es jcdavola31@gmail.com , Muchas Gracias", 
  "gracias andrescarnederes@headset.cl", "Me apunto, muchas gracias mi direcciÃ³n luciana.chavela.ecuador@gmail.com me serÃ¡ de mucha utilidad. "
  )
  </code></pre>
  
  <p>From <a href="https://stackoverflow.com/questions/3194407/extract-all-email-addresses-from-some-txt-documents-using-ruby">this</a> question in SO I got a starting point to extract the emails (@Aaron Haurun's answer), which slightly modified (I added a <code>[\w.]</code> before the <code>@</code> to address emails with <code>.</code> between names) worked well in regex101.com to extract the emails. However, it fails when I port it to <code>gsub</code>:</p>
  
  <pre><code>&gt; gsub("()(\\w[\\w.]+@[\\w.-]+|\\{(?:\\w+, *)+\\w+\\}@[\\w.-]+)()", 
         "\\2", 
         a[1:5], 
         perl = FALSE) ## It doesn't matter if I use perl = TRUE
  
  [1] "buenas tardes. excelente. por favor a: Saolonm@hotmail.com"           "26.leonard@gmail.com "                                                                          
  [3] "Aprecio tu aporte , mi correo es jcdavola31@gmail.com , Muchas Gracias"                           "gracias andrescarnederes@headset.cl"                                                                       
  [5] "Me apunto, muchas gracias mi direcciÃ³n luciana.chavela.ecuador@gmail.com me serÃ¡ de mucha utilidad. "
  </code></pre>
  
  <p>What am I doing wrong and how can I grab those emails? Thanks!</p>