> Brainf*ck
Regular expressions look a lot like Brainfuck. A little trick is to break regexps up
into
various
lines
that
do
different
things
Regular expressions look a lot like Brainfuck. A little trick is to break regexps up
into
various
lines
that
do
different
things
I'm sorry, have you ever seen a regular expression? No they do not.
BTW: that's what I'm doing when programming in kdb+/q (APL family language), even though it's less idiomatic. But I prefer readability and maintainability over succinctness.
---
[1]
var urlRegex = new RegExp(
/(?:(?:(https?|ftp):)?\/\/)/.source // protocol
+ /(?:([^:\n\r]+):([^@\n\r]+)@)?/.source // user:pass
+ /(?:(?:www.)?([^/\n\r]+))/.source // domain
+ /(\/[^?\n\r]+)?/.source // request
+ /(\?[^#\n\r]*)?/.source // query
+ /(#?[^\n\r]*)?/.source // anchor
);