I would like to split "2015-05-13T20:41:29+0000" into 2015-05 and 20:41:29+0000. I tried the following:
> strsplit("2015-05-13T20:41:29+0000",split="-\\d\\dT",fixed=TRUE)
[[1]]
[1] "2015-05-13T20:41:29+0000"
but the pattern is not matched. How to fix this?
$ means "Match the end of the string" (the position after the last character in the string).
In other words, square brackets match exactly one character. (a-z0-9) will match two characters, the first is one of abcdefghijklmnopqrstuvwxyz , the second is one of 0123456789 , just as if the parenthesis weren't there. The () will allow you to read exactly which characters were matched.
Two types of regular expressions are used in R, extended regular expressions (the default) and Perl-like regular expressions used by perl = TRUE . There is also fixed = TRUE which can be considered to use a literal regular expression.
You can remove the fixed
since you are not using exact matching,
strsplit("2015-05-13T20:41:29+0000",split="-\\d{2}T")
# [[1]]
# [1] "2015-05" "20:41:29+0000"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With