最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

字符串转成正则表达式

IT圈 admin 4浏览 0评论

字符串转成正则表达式

方案:使用new RegExp 或 eval,要注意特殊字符转义 和 贪婪匹配

// menu.path  /gatewa/*
// 正则贪婪匹配const reg =menu.path && new RegExp(`^${menu.path.replace(/\//g, '\\/').replace(/\*/g, '[\\d\\w-]*')}$`);

字符串转成正则表达式

方案:使用new RegExp 或 eval,要注意特殊字符转义 和 贪婪匹配

// menu.path  /gatewa/*
// 正则贪婪匹配const reg =menu.path && new RegExp(`^${menu.path.replace(/\//g, '\\/').replace(/\*/g, '[\\d\\w-]*')}$`);

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论