-2

I'm trying to replicate a Reg Ex.. But my code is giving always true irrespective of the value i pass..

It would be much helpful.. if u can explain what exactly this reg Ex is doing...

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

if(re.test('valueFromHtml'){
 console.log("valid");
}else{
    console.log("invalid");
}
Mahesh
  • 107
  • 6
  • Possible duplicate of [Reference - What does this regex mean?](http://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean) — why not simply use an online tool like [RegEx101](https://regex101.com/#javascript)? – Sebastian Simon May 01 '16 at 13:10

1 Answers1

2
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.

Pointy
  • 371,531
  • 55
  • 528
  • 584