Reference · Parsing, formatting and shared types
buildRegexFromDictfunction
A regular expression matching any key of a dictionary as a whole word, longest first. Words match in any alphabet,
so québec is found at the start of a string and al is not found inside Montréal.
Import it
import { buildRegexFromDict } from "@johnmorrisdotca/address-plus";
Definition
function buildRegexFromDict(dict: Record<string, string>, capture?: boolean): RegExp
Parameters
| Name | Type | Description |
|---|---|---|
dict | Record<string, string> | The dictionary whose keys are matched. |
capture (optional) | boolean | Whether to wrap the alternatives in a capturing group; default |
Returns
RegExp
The expression, case-insensitive.
Examples
import { buildRegexFromDict } from "@johnmorrisdotca/address-plus";
console.log(buildRegexFromDict({ street: "St", avenue: "Ave" }).test("avenue"));
// → truetrueWhat it prints (run when this page was built)