I want a regular expression that validates a string of length 1 which has either the characters A
or B
(case insensitive) at the Begin
So this should return true
A
a
B
b
Any word would not match, so the following would return false:
"America"
"Bi"
"a door"
To disable case-sensitive matching for regexp , use the 'ignorecase' option.
Case-insensitive comparison means equating strings irrespective of their case.
(? i) makes the regex case insensitive. (? c) makes the regex case sensitive.
By default, the comparison of an input string with any literal characters in a regular expression pattern is case-sensitive, white space in a regular expression pattern is interpreted as literal white-space characters, and capturing groups in a regular expression are named implicitly as well as explicitly.
You can use /^[AaBb]$/
. That's the simplest I know.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With