regex - RexExp in javascript dont match a number inside a string -
im learning regular expresions in javascript , there thing dont understand.
the following regexp should match string z if add number says correct
var patron = /[a-za-z]/; var regex = new regexp(patron); var v= "hello word 512"; if(v.match(regex)) { //should not match }else { objinput.style.color = "red"; } and them tried this:
var patron = /[a-za-z\d]/; var regex = new regexp(patron); var v= "hello word 512"; if(v.match(regex)) { //should not match still dont work }else { objinput.style.color = "red"; } and also, parentheses not being match
var patron = /[a-za-z\"\']/; var regex = new regexp(patron); var v= "hello word 512"; if(v.match(regex)) { //it match whenever double quoute followed single quoute' }else { objinput.style.color = "red"; }
about first example provided, regex /[a-za-z]/ checks character in input string. since finds h in input string, returns true. need place start , end anchors, ^ , $ in regex. new regex this:
/^[a-za-z]+$/ you can make changes regex accordingly.
match parentheses, need escape them backslash. \( match (, , \) match ).
Comments
Post a Comment