← Resources RESOURCE
Five regex mistakes beginners often run into, and how to fix them.

First, forgetting to escape the dot (.). In regex the dot means "any single character," so to find an actual period you must write \. . For example, when looking for the file extension .txt, if you don't write \.txt then things like xtxt will also be caught.

Second, catching too much with greedy matching. <.*> swallows everything from the first < to the last >. To catch one tag at a time, use the lazy <.*?> or the negated character class <[^>]*>.

Third, leaving out anchors. To validate that an entire string matches a format, you must pin both ends with ^ and $. Without anchors, a string passes even if only part of it matches, which breaks password and username validation.

Fourth, over-escaping special characters inside brackets. Inside a character class [], most metacharacters are treated as plain characters, so [.+*] means the three symbols themselves. That said, ] ^ - \ do require care about their position.

Fifth, forgetting the flags. You need g to find all matches, i to ignore case, and m to apply ^·$ to each line in multi-line text. If you only get one result, check the g flag first.