3 ms·
That does not work so well if you're working in a team. A fairly complex regular expression is always hard to read. We see this as early as in code review and
by patal 6y ago
That does not work so well if you're working in a team. A fairly complex regular expression is always hard to read.
We see this as early as in code review and as late as when you find a production bug because expectations of the surrounding code have changed.
For those reasons, we usually break regexes into parts anyway, and name and comment the single parts. Using the library's example, we might have:
protocol = "^(?:http)(?:s)?"
protocol_separator = "(?:\:\/\/)"
url = "(?:www\.)?(?:[^\ ]*)$"
regex = protocol + protocol_separator + url
Which turns out to be in the direction of these Java Verbal Expressions. I find the Verbal Expressions idea really enlightening.