Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With Javascript how would I search the first three letters in a string and see if they match "ABC"?

Tags:

javascript

With Javascript how would I search the first three letters in a string and see if they match "ABC"? Thanks

like image 464
user133466 Avatar asked Aug 12 '09 17:08

user133466


1 Answers

Using a regular expression:

str.match(/^ABC/);

or using the substring method:

str.substring(0, 3) == 'ABC';
like image 182
Sinan Ünür Avatar answered Sep 30 '22 18:09

Sinan Ünür