I have a form string
stamp = "section_d1_2010-07-01_08_00.txt"
and would like to be able to extract some of this. I was able to do this using repeated str_extract to go to the section I want, for example. grab a month
month = str_extract(stamp,"2010.+")
month = str_extract(month,"-..")
month = str_extract(month,"..$")
however, this is terribly inefficient and there should be a better way. In this particular example, I can use
month = substr(stamp,17,18)
however, we are looking for something more universal (in the case of a change in the number of digits).
I think I need a regular expression to grab what appears AFTER certain flags (_ or -, or 3rd, etc.). I also tried using sub, but had the same problem that I needed a few to hone what I really wanted.
An example of how you can say that the month (07 here) and hour (08 here) will be evaluated.
source