Javascript RegEx - Start and End of String Anomalies -
Javascript RegEx - Start and End of String Anomalies -
so im trying basic regex out first time , i've been told theres few ways of stating start , end of string.
one way '\a
' & '\z
' , other '^
' & '$
'.
for reason when running in js, later alternative works.
does know why might please?
var str = "123456", pattern1 = new regexp("^\\d{6}$"), pattern2 = new regexp("\a\\d{6}\z"); if(pattern1.test(str)){ alert('pattern 1 match!'); }else{ alert('pattern 1 no match!'); } if(pattern2.test(str)){ alert('pattern 2 match!'); }else{ alert('pattern 2 no match!'); }
i think whoever told \a
, \z
supposed work misinformed. based on javascript regular expressions documentation, ^
, $
should work.
javascript regex
Comments
Post a Comment