ajv icon indicating copy to clipboard operation
ajv copied to clipboard

regex for Emoji script unicode not working

Open SimonVillage opened this issue 1 year ago • 3 comments

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.

SimonVillage avatar Aug 02 '22 16:08 SimonVillage

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...

epoberezkin avatar Aug 03 '22 20:08 epoberezkin

Did you check the example? https://regex101.com/r/ZEU1fo/1

It says \p{Emoji} matches any characters in the Emoji script

SimonVillage avatar Aug 04 '22 06:08 SimonVillage

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.

epoberezkin avatar Aug 04 '22 07:08 epoberezkin

https://runkit.com/esp/630fbcad0fa3250008968a19

it works with escaping

epoberezkin avatar Aug 31 '22 20:08 epoberezkin