首页 > 编程语言 >微信小程序 正则字符串转为正则对象

微信小程序 正则字符串转为正则对象

时间:2023-03-28 17:02:25浏览次数:34  
标签:regex 对象 微信 正则 字符串 match

场景:
服务器返回的一个正则表达式是一个字符串类型的, 直接拿去配置正则是不可以的, 需要转为正则对象, 然后去验证, 网页可以使用evel()对象, 但是微信小程序就不行,
方式如下:

        let regex = regExpString.match(/^\/([\S\s]+)\/([gim]{0,3})$/);
        regex = regex || [, regex, ""];      // If the previous match is null,
                                             // treat the string as a slash-less RegEx
        regex = new RegExp(regex[1], regex[2]);
        console.log('转换后的正则表达式', regex)

原文地址: https://www.oomake.com/question/2225716

标签:regex,对象,微信,正则,字符串,match
From: https://www.cnblogs.com/ybixian/p/17265882.html

相关文章