A voltage regulator is a component that gives you a stable output voltage, no matter if the input voltage changes. It’s an integrated circuit (IC), usually with three or more pins.
A typical example of when you need a voltage regulator is if all you have is a 9V battery, but your device needs 5V. A voltage regulator can take those 9V as input and create a nice and stable 5V output that you can use to power your device.
Or if you need different voltage levels for a circuit you’re building. Let’s say you have a circuit with a microcontroller that needs 5V and a motor that needs 12V. Instead of using two power supplies, you can use just one 12V supply and add a voltage regulator to provide 5V for the microcontroller.