Let's advance a bit in our regexes (that's an abbreviation for regular expressions!)!
To match any character, use a dot, e.g.:
grepl("^Ira.$", countries)
will find 4-letter countries that start with "Ira".
grepl("^......$", countries)
And that one will find all 6-letter countries.
You can build even more complicated regular expressions with asterisk or plus sign.
An asterisk (*
) will match the preceding pattern 0 or more times. For example:
grepl("^C[[:alpha:]]*a", countries)
will match all countries starting with "C" and ending with "a", and have 0 or more letters in between.
A plus (+
) will match the preceding pattern 1 or more times. For example:
grepl("[[:digit:]]+", countries)
will find country names with at least one digit.
So? What will match .*
? Either no characters or any number of characters!