3 ms·
Regular expressions aren't difficult. People think regular expressions are difficult because they're taught either not at all, or very badly. If you learn them
by Planktonne 4y ago
Regular expressions aren't difficult.
People think regular expressions are difficult because they're taught either not at all, or very badly. If you learn them deliberately, moving through the unfolding complexity of patterns, they're actually both beautiful and intuitive.
I think most programmers first come to regular expressions when they encounter a problem that can't be efficiently solved in any other way. The sort of problem that can only be solved by regex is also the sort of problem which is solved by complex regex. This means that the first introduction is to be thrown right in at the very, very deepest end. Regex becomes a confusing and arcane thing, and the programmer resolves to rarely use them.
However, it doesn't have to be like that. If you teach regex before they're 100% required - when they're used to solve problems that are biddable and have multiple possible solutions - you can start to get a feel for the syntax. That makes regex feel accessible, and soon you can start to work with even the complex ones.