Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Match only A or B case insensitive

Tags:

regex

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"
like image 535
Richard Pérez Avatar asked Jul 05 '11 17:07

Richard Pérez


People also ask

How do you match a word with a case insensitive in regex?

To disable case-sensitive matching for regexp , use the 'ignorecase' option.

What is case insensitive matching?

Case-insensitive comparison means equating strings irrespective of their case.

How do you make regex not case-sensitive?

(? i) makes the regex case insensitive. (? c) makes the regex case sensitive.

Are regex matches 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.


1 Answers

You can use /^[AaBb]$/. That's the simplest I know.

like image 190
SteeveDroz Avatar answered Sep 18 '22 19:09

SteeveDroz