I am trying to extract the first four digits after a hyphen in the following string: extract_public_2018_20190530180949469_58906_20110101-20111231Texas
. I am using the following code:
stringr::str_extract(
"extract_public_2018_20190530180949469_58906_20110101-20111231Texas",
"-[[:digit:]]{4}"
)
But I get -2011
instead of 2011
. How can I only extract the four digits and not the hyphen?