This is a real word example. I had data that had dates embedded in the filenames and wanted to move it to the start of the file instead of it being in the middle.
Below represents the matching portion of this issue (not the substitution portion). It also matches the dashes around it , this is because they need to be removed when we eventually move the date around.
NOTE: This will match the formats 2020 Year and 2020-02 Year Range.
REGEX:
(?:-+)?(\d{4}(?:-\d{2})?)(?:-+)?
MATCHING DATA:
Class-List-Year-1-2019-20-external-use.pdf
Class-List-Year-1-2020-21-external-use.xlsx
Class-List-Year-2-2019-20-external-use.pdf
Class-List-Year-2-2020-21-external-use.xlsx
Class-List-Year-3-2019-20-external.pdf
Class-List-Year-3-2020-21-external-use.xlsx
Class-List-Year-4-2019-20-external.pdf
Class-List-Year-4-2020-21-external-use.xlsx
TEST-Class-List-2020-External.pdf
TEST-Class-list-2021-External-use.xlsx
2020-21βClass-List-Year-1-external-use.xlsx
2020-21βClass-List-Year-1-external-use.xlsx
2020-21-Class-List-Year-1-external-use.xlsx