I'm looking to extract the year from a string. This always comes after an 'X' and before "." then a string of other characters.
Using stringr
's str_extract
I'm trying the following:
year = str_extract(string = 'X2015.XML.Outgoing.pounds..millions.'
, pattern = 'X(\\d{4})\\.')
I thought the brackets would define the capture group, returning 2015
, but I actually get the complete match X2015.
Am I doing this correctly? Why am i not trimming "X" and "."?