What is astral-regex?
The astral-regex npm package is designed to provide a regular expression for matching astral symbols in text. Astral symbols are Unicode symbols that consist of a pair of surrogate halves and are used to represent characters outside the Basic Multilingual Plane (BMP). This package is particularly useful for applications that need to process, validate, or manipulate text containing such symbols, ensuring compatibility with the full range of Unicode characters.
What are astral-regex's main functionalities?
Matching astral symbols
This feature allows you to match and extract astral symbols from a string of text. The code sample demonstrates how to use the package to find astral symbols within a given string. In this example, the astral symbol '𠮷' is successfully matched and extracted from the text.
"𠮷野家".match(astralRegex()); // Returns ['𠮷']
Other packages similar to astral-regex
emoji-regex
The emoji-regex package provides a regular expression to match Unicode emoji characters. While astral-regex is focused on matching any astral symbol, emoji-regex specializes in emojis, which are a subset of astral symbols. This makes emoji-regex more suitable for applications specifically dealing with emoji processing.
xregexp
XRegExp is an extended JavaScript regex library that, among other enhancements, provides support for Unicode including astral symbols. Compared to astral-regex, XRegExp offers a broader range of regex features and capabilities, making it a more versatile choice for complex text processing tasks that require beyond basic astral symbol matching.
astral-regex
Regular expression for matching astral symbols
Install
$ npm install astral-regex
Usage
const astralRegex = require('astral-regex');
astralRegex({exact: true}).test('🦄');
'foo 🦄 💩 bar'.match(astralRegex());
API
astralRegex([options])
Returns a RegExp
for matching astral symbols.
options
Type: Object
exact
Type: boolean
Default: false
(Matches any astral symbols in a string)
Only match an exact string. Useful with RegExp#test()
to check if a string is a astral symbol.
License
MIT © Kevin Mårtensson