[R] Regexp: extract first occurrence of date in string

johannes rara johannesraja at gmail.com
Sat Jan 2 16:08:25 CET 2010


I would like to extract first date from a string:

> txt <- "first date is 05.12.2009. Second date is 06.12.2009."
> txt
[1] "first date is 05.12.2009. Second date is 06.12.2009."

I tried:

> sub("^.*?\\s(\\d{1,2}\\.\\d{1,2}\\.\\d{4})", "\\1", txt, extended=T, perl=T)
[1] "05.12.2009. Second date is 06.12.2009."
>

How to modify this?

-J



More information about the R-help mailing list