Creating a regular expression to match the street address

Recall that in the street address, you are looking for the following pattern:

<street number> <initial street name> <street suffix>

The first part of the pattern string should match the street number. The street number is a sequence of digits located at the beginning of the string. For the sake of this exercise, I will ignore street addresses that contain letters (such as 10A or 10B) or ranges (such as 110-120). The following should be sufficient to capture the street address:

  • A ^ symbol to indicate the beginning of the string
  • A [0-9] range to indicate the range of all digits
  • A + symbol following the digit range to indicate an indefinitely long sequence of digits
  • A \s+ symbol to indicate ...

Get Practical Data Wrangling now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.