[R] Help with Regular expression

Rui Barradas ruipbarradas at sapo.pt
Wed Jan 3 20:50:33 CET 2018


Hello,

I believe the following regex will do it.

x <- "\":\"03-JAN-2018 16:00:00\""

sub('^.*(\\d{2}-\\w{3}-\\d{4} \\d{2}:\\d{2}:\\d{2})[:"]', '\\1', x)


Hope this helps,

Rui Barradas

On 1/3/2018 2:26 PM, Christofer Bogaso wrote:
> Hi,
> 
> I was working on following expression :
> 
> "\":\"03-JAN-2018 16:00:00\""
> 
> 
> This is basically a combination of Date and Time mixed with some Noise.
> 
> I want to extract only Date and Time part i.e. "03-JAN-2018 16:00:00
> 
> I tried following :
> 
> gsub("![0-9][0-9]-[a-zA-Z][a-zA-Z][a-zA-Z]-[0-9][0-9][0-9][0-9]
> [0-9][0-9]:[0-9][0-9]:[0-9][0-9]", "", "\":\"03-JAN-2018 16:00:00\"",
> ignore.case = TRUE)
> 
> Obviously, with above code, I am removing that portion of my string
> which I actually I wanted!
> 
> How can I reverse above code, so that I will be removing that portion
> of my string which I actually I ***NOT*** wanted?
> 
> Thanks for your time.
> 
> Happy New Year!
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list