1.1.0 • Published 2 years ago

unicode-word-regex v1.1.0

Weekly downloads
-
License
Unlicense
Repository
github
Last release
2 years ago

unicode-word-regex

A big regex to match unicode words.

Published as a library so to reduce duplication when several other libraries use this same hack. This library has zero dependencies and the regex weighs 7kB.

Ideally, we could just use modern RegExp Unicode Property Names such as /\p{Letter}+/u, which is supported in modern browsers and all Node.js LTS versions. However, nodejs-mobile is an important target in some cases, and it is compiled with --with-intl=none https://github.com/JaneaSystems/nodejs-mobile/issues/82 which means that Unicode Property Names are not supported. So, unfortunately, we have to expand all possible character ranges.

The regex in the source code is generated from the script ./generate-regex.js.

Install

npm install unicode-word-regex

Example

This library exports a function that generates the regex for you.

const getUnicodeWordRegex = require('unicode-word-regex');

const regex = getUnicodeWordRegex();
console.log(regex.test('elämä')); // true

License

Unlicense