正则表达式不起作用,因为模式是字符串 [英] Regular Expression is not working due to the pattern is string

查看:115
本文介绍了正则表达式不起作用,因为模式是字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个框架,在框架中工作的正则表达式像这样的var regex = "/^0(9|4)\d{8}$/";一样以String的形式出现,当我尝试工作时,我无法进行此工作,有没有办法可以转换字符串正常的RegEx https://plnkr.co/edit/Yjch7G7npkHmtKYDF5Yc?p=preview

i am using an framework where in the frame work the regular expression for mat is coming as String like this var regex = "/^0(9|4)\d{8}$/"; when i try to work i cant able to work on this is there any way that the string can be convert to normal RegEx https://plnkr.co/edit/Yjch7G7npkHmtKYDF5Yc?p=preview

当我尝试使用此新RegExp将我的经验值从

when i try to use this new RegExp to convert my expresiion changed from this to

/^0(9|4)d{8}$/

这个

/\/^0(9|4)d{8}$\//

由于这种转化

new RegExp($(element).attr("data-regex")); = /\/^0(9|4)d{8}$\//

推荐答案

尝试删除双引号并替换为html编码字符.这样,JavaScript不会在语言解释中使用双引号.

Try removing the double quotes and replacing with the html encoded character. That way JavaScript wont use the double quotes as part of its language interpretation.

尝试将ascii值"用作,也可以使用"

Try using ascii value " for " or you can use "

这篇关于正则表达式不起作用,因为模式是字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆