简体   繁体   English

如何匹配 unicode 字符正则表达式

[英]How to match unicode character regex

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.我一直无法弄清楚如何匹配ʀ unicode 字符。

I tried \\p{L} as noted in another SO post.正如另一篇 SO 帖子中所述,我尝试了\\p{L} Also tried putting u for unicode as a modifier.还尝试将 unicode 的u作为修饰符。

Use \p{L} in conjunction with the flags gu :\p{L}与标志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.请获取字符的 Unicode 并使用以下模式。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM