With Javascript, how will I look for the first three letters in a string and see if they match "ABC"?

With Javascript, how will I look for the first three letters in a string and see if they match "ABC"? Thanks

+4
source share
3 answers

Using regex:

str.match(/^ABC/); 

or using the substring method:

 str.substring(0, 3) == 'ABC'; 
+10
source
 if (/^ABC/.test(aString)) { } 
+3
source
 "ABCDEF".match(/^ABC/) 
0
source

All Articles