ajv
ajv copied to clipboard
regex for Emoji script unicode not working
JSON Schema
const schema = {
body: {
type: "object",
properties: {
emoji: {
type: "string",
pattern: "^\p{Emoji}$",
},
},
},
};
Sample data
{
"emoji": "😜"
}
Regex test: https://regex101.com/r/ZEU1fo/1
I assume it has something to do with the \p
? I believe that I just can't figure out how to write it the right way.
This is not a bug, and not an issue with the library - please review the docs on regular expressions.
The regex does seem incorrect - I don't thing {Emoji} regex would match any emoji, and not sure what \p does here...
Did you check the example? https://regex101.com/r/ZEU1fo/1
It says \p{Emoji} matches any characters in the Emoji script
If that works, then maybe all you need is to escape back slash? Because currently you are escaping p, so \ is not part of the string.
https://runkit.com/esp/630fbcad0fa3250008968a19
it works with escaping