-2

I have a string: "C:/This/is/a/windows/path/file20110312name20120221.csv".

I want to extract all dates (e.g. [0-9]{8}).

Generally, how can I extract sub-strings matching a pattern from a bigger string?

orde
  • 5,233
  • 6
  • 31
  • 33
statquant
  • 13,672
  • 21
  • 91
  • 162

1 Answers1

6

It is advised to supplement your question with a reproducible example (How to make a great R reproducible example?)

Is this what you look for ?

s <- "C:/This/is/a/windows/path/file20110312name20120221.csv"
regmatches(s, gregexpr("[0-9]{8}", s))
Community
  • 1
  • 1
Karl Forner
  • 4,175
  • 25
  • 32