Regexes match patterns. Anchors `^`/`$` bound the whole string, character classes and quantifiers describe shape, and flags such as `i` and `g` change behaviour.
const isAddress = /^0x[a-fA-F0-9]{40}$/;
isAddress.test(input);Beware the `g` flag with `test`: it keeps `lastIndex` state between calls. Keep patterns simple and readable.