We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 876428d commit 999f44dCopy full SHA for 999f44d
javascript/es6/regexp-emoji.md
@@ -0,0 +1,53 @@
1
+# Matching Emoji in RegExp
2
+
3
+`\p{Emoji}` + `u` flag
4
5
+* Example:
6
7
+```
8
+function countEmoji(input) {
9
+ const c = input.match(
10
+ /\p{Emoji}/gu
11
+ );
12
13
+ return (c || []).length;
14
+}
15
16
17
+countEmoji('xd 😱🤠 hehe 🙃 🤕')
18
+// 4
19
20
+countEmoji('źć auuu')
21
+// 0
22
23
+countEmoji('x🐍x')
24
+// 1
25
26
+countEmoji('👍')
27
28
29
30
+## `\P{Emoji}`
31
32
+To match all but emoji use `\P{Emoji}`:
33
34
35
+function leaveOnlyEmoji(input) {
36
+ return input.replace(
37
+ /\P{Emoji}/gu, ''
38
39
40
41
42
+leaveOnlyEmoji('xd 😱🤠 hehe 🙃 🤕')
43
+// '😱🤠🙃🤕'
44
45
+leaveOnlyEmoji('źć auuu')
46
+// ''
47
48
+leaveOnlyEmoji('x🐍x')
49
+// '🐍'
50
51
+leaveOnlyEmoji('👍')
52
+// '👍'
53
0 commit comments