December 2023
Intermediate to advanced
242 pages
5h 28m
English
| Recipe 53 | Matching Unicode Word Boundaries with the Unicode Property Escape |
Suppose you want to search a document for the Portuguese word “vã,” which means “go,” without matching other words that contain “vã,” such as “vão.” To achieve this, you try using word boundaries to isolate the word “vã” from other words containing similar characters:
| | const re = /\bvã\b/; |
| | |
| | "vão".match(re); |
| | // → ["vã", index: 0, input: "vão bem", groups: undefined] |
| | |
| | "vã bem".match(re); |
| | // → null |
But, your regex is matching the opposite of your intended result. The problem is that the word boundary (\b) considers accented characters such as “ã” as non-word characters. You need an alternative ...
Read now
Unlock full access