End of Summer - hours only!Up to 80% off on all courses and bundles.-Close
Strings basics
Regular expressions
Modifying strings


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!


Using your knowledge from previous exercises as well as from this one, extract all country names that start with "G" and end with an "a".

Stuck? Here's a hint!

Here's the regex you'll need: ^G.*a$.