I am trying to write a regular expression that will require 3 characters or empty.
I start with ^[A-Z]{3}$ but I have no idea how to end it.
I am trying to write a regular expression that will require 3 characters or empty.
I start with ^[A-Z]{3}$ but I have no idea how to end it.
You may use an alternation here:
^(?:[A-Z]{3}|)$
This pattern says to match:
^ from the start of the input
(?:
[A-Z]{3} 3 uppercase letters
| OR
(empty)
)$ end of the input