Fix: 正则 Unified_Ideograph 类浏览器不识别问题

安装依赖

yarn add regexpu-core

yarn add @babel/plugin-proposal-unicode-property-regex --dev

babel.config.js

module.exports = {
  presets: [
    '@vue/app',
  ],
  plugins: [
    [
      '@babel/plugin-proposal-unicode-property-regex',
      {
        useUnicodeFlag: true,
      },
    ],
  ],
};

tools.js

const rewritePattern = require('regexpu-core');
const _regexpu = rewritePattern('\\p{Unified_Ideograph}', 'u', {
	'unicodePropertyEscape': true, 
	'useUnicodeFlag': false,
})

const regex = new RegExp(_regexpu, 'u');
if (regex.test(item)) {
	// 验证通过
}

你可能感兴趣的:(兼容处理方案)