How to match unicode character regex

Viewed 72

I have the input and regex of

  const input = `iPhone Xʀ`;
  
  console.log(input.match(/^([\w\d\-\s]*)/));

I have not been able to figure out how to match the ʀ unicode character.

I tried \\p{L} as noted in another SO post. Also tried putting u for unicode as a modifier.

2 Answers

Use \p{L} in conjunction with the flags gu:

const input = `iPhone Xʀ`;
console.log(input.match(/^([\w\d\-\s]*\p{L})/gu));
  
// output:

// [
//  "iPhone Xʀ"
// ]

Please get the Unicode of the character and use the following pattern.

  const input = `iPhone Xʀ`;
  console.log(input.match(/^([\w\d\-\s]*)\x{0280}/));
Related