Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Strings basics
Regular expressions
Modifying strings
Summary

Instruction

Can we check if the string contains numbers or letters? We can, using these special regular expressions:

  • [[:digit:]] – matches numbers.
  • [[:alpha:]] – matches letters, regardless of case.

To see city names which contain digits, we write:

cities[grepl("[[:digit:]]", cities)]

Psst! Here's a faster way to write those regexes (regular expresions):

  • Use "\\d" instead of "[[:digit:]]" to match numbers.
  • Use "\\w" instead of [[:alpha:]] to match "word" characters – letters, regardless of case.
cities[grepl("\\d", cities)]

Exercise

We have a vector with some of our clients' addresses, and some addresses are quite detailed. We need to find which strings contain numbers as well as street names.

Display strings in the addresses vector containing numbers.