What is the difference between `^` and `$` in a regex?
`^` marks the start of the text (or of each line, with the `m` flag) and `$` marks the end; neither consumes a character, so an anchor alone never appears in the matched text, it only restricts where the rest of the pattern can start or end.
What does the `g` flag change in a regex result?
Without `g`, the test stops at the first match found in the text; with `g`, it keeps searching after each match and returns every occurrence, which is required to extract, for example, every number in a text instead of just the first.
Why can a regex freeze the browser?
A pattern with nested groups and overlapping quantifiers (like `(a+)+b` against text with no `b`) can trigger catastrophic backtracking, where the engine tries a number of combinations that grows exponentially with the text length; that is why a regex tester caps the number of matches returned, to keep a pathological pattern from freezing the tab.
How do you validate a UUID with regex without accepting any hyphenated string?
Restrict the version nibble to `[1-5]` at the right spot (right after the second hyphen) and the variant nibble to `[89ab]` (right after the third), as RFC 4122 defines; without those 2 specific classes, the pattern accepts any correctly-shaped hexadecimal sequence, even one that is not a real UUID.