Skip to content

Commit 40e05ea

Browse files
authored
docs: add Unicode RegExp alternative to emoji-regex (#234)
1 parent a0fccf8 commit 40e05ea

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

docs/modules/emoji-regex.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,19 @@ There are alternative packages to `emoji-regex` whilst being smaller in package
1111
[Project Page](https://github.com/slevithan/emoji-regex-xs)
1212

1313
[npm](https://npmjs.com/package/emoji-regex-xs)
14+
15+
## Unicode RegExp (native)
16+
17+
If your target runtime supports ES2024 Unicode property sets, you can use the native [`\p{RGI_Emoji}`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Unicode_character_class_escape) property in a regular expression. This relies on the engine's built‑in Unicode handling.
18+
19+
```ts
20+
import emojiRegex from 'emoji-regex'
21+
22+
const regex = emojiRegex()
23+
const regex = /\p{RGI_Emoji}/gv
24+
25+
for (const match of text.matchAll(regex)) {
26+
const emoji = match[0]
27+
console.log(`Matched sequence ${emoji} — code points: ${[...emoji].length}`)
28+
}
29+
```

0 commit comments

Comments
 (0)