Module 17 of 33 · Media
Alternatives and optionals
Alternatives and optionals
With a ? question mark, we can specify that a part of the string is optional and could be additionally accepted if there, but not mandatory.
The main difference between optionals and alternatives is that optionals mean, that either this character will be put or nothing, alternatives in contrast mean either the one, or the other one. But in the end for sure something. Nothing is not an option.
If we don't want to have partial match we can specify that the string that we are testing on should should begin and end with the pattern we have, and it is not a subset of a bigger string. To specify that this is the beginning we do it with the ^ character, and the end with a $ dollar sign character.