vendredi 17 octobre 2014

Javascript RegEx - Start and End of String Anomalies


Vote count:

0




So im trying some really basic RegEx out for the first time and I've been told that theres a few ways of stating the start and end of the string.


One way would be '\A' & '\Z' and the other would be '^' & '$'.


For some reason when running this in JS, the later is the only option that actually works.


Does anyone know why that might be please?



var str = "123456",
pattern1 = new RegExp("^\\d{6}$"),
pattern2 = new RegExp("\A\\d{6}\Z");
// pattern2 = /^\d{6}$/;

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!');
}


asked 22 secs ago







Javascript RegEx - Start and End of String Anomalies

Aucun commentaire:

Enregistrer un commentaire