I have to match a string by it's first two letters using Regex to check a specific two characters available as the first two letters of a string. Here assume that the first two characters are 'XX'.
And the strings I need to match are
- ABCDS
- XXDER
- DERHJ
- XXUIO
So I need to filter this list to get strings that only starts with 'XX'
code I tried so far
var filteredArr = [];
var arr = [ "ABCDS ", "XXDER ", "DERHJ ", "XXUIO" ];
var re = new RegExp('^[a-zA-Z]{2}');
jQuery.each( arr, function( i, val ) {
if(re.test(val )){
filteredArr.push(val);
}
});
What will be the exact Regex pattern to check the string that starts with 'XX'
indexOf