basant307/AI_Governance_Project
048
1# emoji-regex [](https://travis-ci.org/mathiasbynens/emoji-regex)2 3_emoji-regex_ offers a regular expression to match all emoji symbols and sequences (including textual representations of emoji) as per the Unicode Standard.4 5This repository contains a script that generates this regular expression based on [Unicode data](https://github.com/node-unicode/node-unicode-data). Because of this, the regular expression can easily be updated whenever new emoji are added to the Unicode standard.6 7## Installation8 9Via [npm](https://www.npmjs.com/):10 11```bash12npm install emoji-regex13```14 15In [Node.js](https://nodejs.org/):16 17```js18const emojiRegex = require('emoji-regex/RGI_Emoji.js');19// Note: because the regular expression has the global flag set, this module20// exports a function that returns the regex rather than exporting the regular21// expression itself, to make it impossible to (accidentally) mutate the22// original regular expression.23 24const text = `25\u{231A}: β default emoji presentation character (Emoji_Presentation)26\u{2194}\u{FE0F}: βοΈ default text presentation character rendered as emoji27\u{1F469}: π© emoji modifier base (Emoji_Modifier_Base)28\u{1F469}\u{1F3FF}: π©πΏ emoji modifier base followed by a modifier29`;30 31const regex = emojiRegex();32let match;33while (match = regex.exec(text)) {34 const emoji = match[0];35 console.log(`Matched sequence ${ emoji } β code points: ${ [...emoji].length }`);36}37```38 39Console output:40 41```42Matched sequence β β code points: 143Matched sequence β β code points: 144Matched sequence βοΈ β code points: 245Matched sequence βοΈ β code points: 246Matched sequence π© β code points: 147Matched sequence π© β code points: 148Matched sequence π©πΏ β code points: 249Matched sequence π©πΏ β code points: 250```51 52## Regular expression flavors53 54The package comes with three distinct regular expressions:55 56```js57// This is the recommended regular expression to use. It matches all58// emoji recommended for general interchange, as defined via the59// `RGI_Emoji` property in the Unicode Standard.60// https://unicode.org/reports/tr51/#def_rgi_set61// When in doubt, use this!62const emojiRegexRGI = require('emoji-regex/RGI_Emoji.js');63 64// This is the old regular expression, prior to `RGI_Emoji` being65// standardized. In addition to all `RGI_Emoji` sequences, it matches66// some emoji you probably donβt want to match (such as emoji component67// symbols that are not meant to be used separately).68const emojiRegex = require('emoji-regex/index.js');69 70// This regular expression matches even more emoji than the previous71// one, including emoji that render as text instead of icons (i.e.72// emoji that are not `Emoji_Presentation` symbols and that arenβt73// forced to render as emoji by a variation selector).74const emojiRegexText = require('emoji-regex/text.js');75```76 77Additionally, in environments which support ES2015 Unicode escapes, you may `require` ES2015-style versions of the regexes:78 79```js80const emojiRegexRGI = require('emoji-regex/es2015/RGI_Emoji.js');81const emojiRegex = require('emoji-regex/es2015/index.js');82const emojiRegexText = require('emoji-regex/es2015/text.js');83```84 85## For maintainers86 87### How to update emoji-regex after new Unicode Standard releases88 891. Update the Unicode data dependency in `package.json` by running the following commands:90 91 ```sh92 # Example: updating from Unicode v12 to Unicode v13.93 npm uninstall @unicode/unicode-12.0.094 npm install @unicode/unicode-13.0.0 --save-dev95 ````96 971. Generate the new output:98 99 ```sh100 npm run build101 ```102 1031. Verify that tests still pass:104 105 ```sh106 npm test107 ```108 1091. Send a pull request with the changes, and get it reviewed & merged.110 1111. On the `main` branch, bump the emoji-regex version number in `package.json`:112 113 ```sh114 npm version patch -m 'Release v%s'115 ```116 117 Instead of `patch`, use `minor` or `major` [as needed](https://semver.org/).118 119 Note that this produces a Git commit + tag.120 1211. Push the release commit and tag:122 123 ```sh124 git push125 ```126 127 Our CI then automatically publishes the new release to npm.128 129## Author130 131| [](https://twitter.com/mathias "Follow @mathias on Twitter") |132|---|133| [Mathias Bynens](https://mathiasbynens.be/) |134 135## License136 137_emoji-regex_ is available under the [MIT](https://mths.be/mit) license.138 