unicode-word-regex

1.1.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i unicode-word-regex

Weekly Downloads

2,063

Version

1.1.0

License

Unlicense

Unpacked Size

11.6 kB

Total Files

4

Last publish

Collaborators

  • staltz