3 ms·
yes, if your PL supports multiline regex with end of line comments[1]. BTW: that's what I'm doing when programming in kdb+/q (APL family language), even though
by nivertech 3y ago
yes, if your PL supports multiline regex with end of line comments[1].
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
);