title: Extracting numbers from text with stringr and regex in R
body: <p>I have a problem where I'm trying to extract numbers from a string containing text and numbers and then create two new columns showing the Min and Max of the numbers.</p>
  
  <p>For example, I have one column and a string of data like this:</p>
  
  <pre><code>Text
  Section 12345.01 to section 12345.02
  </code></pre>
  
  <p>And I want to create two new columns from the data in the Text column, like this:</p>
  
  <pre><code>Min        Max   
  12345.01   12345.02
  </code></pre>
  
  <p>I'm using dplyr and stringr with regex, but the regex only extracts the first occurence of the pattern (first number).</p>
  
  <pre><code>df%&gt;%dplyr::mutate(SectionNum = stringr::str_extract(Text, "\\d+.\\d+"))
  </code></pre>
  
  <p>If I try to use the <code>stringr::str_extract_all</code> function. It seems to extract both occurence of the pattern, but it creates a list in the tibble, which I find is a real hassle. So I'm stuck on the first step, just trying to get the numbers out into their own columns.</p>
  
  <p>Can anyone recommend the most efficient way to do this? Ideally I'd like to extract the numbers from the string, convert them to numbers <code>as.numeric</code> and then run <code>min()</code> and <code>max()</code> functions.</p>