title: parsing regular expression for sub and gsub in r
body: <p>I am having trouble understanding what the regular expressions in the following lines of code mean.</p>
  
  <pre><code>author = "10_1 A Kumar; Ahmed Hemani ; Johnny &amp;Ouml;berg&lt;"
  
  # after some experiment, it looks like this line captures whatever is in
  # front of the underscore.
  authodid =  sub("_.*","",author)
  
  # this line extracts the number after the underscore, but I don't know 
  # how this is achieved
  paperno &lt;- sub(".*_(\\w*)\\s.*", "\\1", author)
  
  # this line extracts the string after the numbers
  # I also have no idea how this is achieved through the code
  coauthor &lt;- gsub("&lt;","",sub("^.*?\\s","", author))
  </code></pre>
  
  <p>I have read on the web that the first argument is the pattern, second is the replacement, and the third is the object to operate on. I also saw a few post on SO and learned that <code>\\w</code> means the a word and <code>\\s</code> is a space. </p>
  
  <p>However, a few things are still unclear. <code>\\w</code> means word, does it mean the next word? If not, how should I interpret it? I learned that <code>^</code> matches the start of the string, but what about the period after <code>^</code>?</p>
  
  <p>More importantly, what is the interpretation of <code>_.*</code> What about <code>.*_</code> How about <code>^.*?\\s</code>? How should I read them?</p>
  
  <p>Thanks!</p>