title: How to replace space with "_" after last slash in a string with R
body: <p>I have a list of strings, and for each string, I need to replace all spaces after the last slash with an "_". Here's a minimum reproducible example.</p>
  
  <pre><code>my_list &lt;- list("abc/as 345/as df.pdf", "adf3344/aer4 ffsd.doc", "abc/3455/dfr.xls", "abc/3455/dfr serf_dff.xls", "abc/34 5 5/dfr 345 dsdf 334.pdf")
  </code></pre>
  
  <p>After doing the replacement, the result should be:</p>
  
  <pre><code>list("abc/as 345/as_df.pdf", "adf3344/aer4_ffsd.doc", "abc/3455/dfr.xls", "abc/3455/dfr_serf_dff.xls", "abc/34 5 5/dfr_345_dsdf_334.pdf")
  </code></pre>
  
  <p>I thought of matching the text after the last slash using regex, and then replace " " for "_", but didn't find a way to implement it.
  It would be something like this:
  <code>gsub(pattern, "_", my_list)</code>,
  in which pattern would be a regex that would be saying: match every space after the last slash (there is at least one slash in every element of the list).</p>