简体   繁体   English

下面的 Reg 表达式有什么问题?

[英]What wrong with the below Reg Expression?

I'm trying to replicate a Reg Ex.. But my code is giving always true irrespective of the value i pass..我正在尝试复制一个 Reg Ex .. 但我的代码总是给出 true ,无论我传递的值如何..

It would be much helpful.. if u can explain what exactly this reg Ex is doing...这会很有帮助..如果你能解释一下这个reg Ex到底在做什么......

 var re = new RegExp("([a-zA-Z0-9-`.'_]?)+"); if(re.test('valueFromHtml'){ console.log("valid"); }else{ console.log("invalid"); }

var re = new RegExp("([a-zA-Z0-9-`.'_]?)+");

Your regular expression means, "one or more occurrences of a member of this particular set of characters, or no characters".您的正则表达式表示“此特定字符集的某个成员出现一次或多次,或者没有出现任何字符”。 Your pattern therefore matches the zero-character empty string, which is part of any possible test string.因此,您的模式匹配零字符的空字符串,它是任何可能的测试字符串的一部分。

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

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