Reference · Parsing, formatting and shared types
CITY_PATTERNSconstant
Patterns for a city of one or more words at the end of a text, after a space, used where no comma marks it. A word is letters of any alphabet, with apostrophes and hyphens inside it.
Import it
import { CITY_PATTERNS } from "@johnmorrisdotca/address-plus";
Definition
const CITY_PATTERNS: { readonly BASIC_CITY: RegExp; readonly MULTI_WORD_CITY: RegExp; readonly SINGLE_WORD_CITY: RegExp; readonly TWO_WORD_CITY: RegExp; } = {
BASIC_CITY: new RegExp(String.raw `\s+(${CITY_WORD}(?:\s+${CITY_WORD})?)$`, "u"),
MULTI_WORD_CITY: new RegExp(String.raw `\s+(${CITY_WORD}(?: ${CITY_WORD})*?)(?:\s+[A-Z]{2,3})?\s*$`, "u"),
SINGLE_WORD_CITY: new RegExp(String.raw `\s+(${CITY_WORD})$`, "u"),
TWO_WORD_CITY: new RegExp(String.raw `\s+(${CITY_WORD}\s+${CITY_WORD})$`, "u"),
} as const
Members
| Name | Type | Description |
|---|---|---|
BASIC_CITY | RegExp | |
MULTI_WORD_CITY | RegExp | |
SINGLE_WORD_CITY | RegExp | |
TWO_WORD_CITY | RegExp |
Examples
import { CITY_PATTERNS } from "@johnmorrisdotca/address-plus";
console.log(CITY_PATTERNS.SINGLE_WORD_CITY.exec("Pine St Tacoma")?.[1]);
// → "Tacoma"TacomaWhat it prints (run when this page was built)