[ACCEPTED]-Reg. Expression checks first letter of a string-regex

Accepted answer
Score: 13

Your expression does not need .* nor should 3 it have the $

'/^([a-zA-Z])/'

In fact, if you don't need 2 to know what this letter is, you could go 1 even simpler:

'/^[a-zA-Z]/'

// These expressions are true
/^[a-zA-Z]/.test("Sample text")

var re = new RegExp('^[a-zA-Z]');
re.test('Sample text');
Score: 2

Try the following:

'/^[a-zA-Z].*$/'

which checks if the first 2 letter is in the alphabet and allows any 1 character after that.

Score: 0

I was able to single out the first letter 3 with this /^[a-zA-Z].*$/ from one of the above answers, but 2 I didn't need the .\*$ so I had /^[A-J]/g (working on 1 my own assignment hence a-j).

More Related questions