[ACCEPTED]-Reg. Expression checks first letter of a string-regex
Accepted answer
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');
Try the following:
'/^[a-zA-Z].*$/'
which checks if the first 2 letter is in the alphabet and allows any 1 character after that.
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).
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.