Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #21078
| From | Andreas Bergmaier <andber93@web.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Recommendation for new RegExp (Array-extra-like) methods |
| Date | 2013-08-28 17:16 +0200 |
| Organization | albasani.net |
| Message-ID | <kvl485$rse$1@news.albasani.net> (permalink) |
| References | <ac07e89f-90ee-4b6d-a524-5adfadd0cb94@googlegroups.com> |
brettz9@gmail.com schrieb:
> I have Array-extra-like methods added to RegExp.prototype at
> https://gist.github.com/brettz9/6366721
I don't see much reason to do so. The method names imply that you are
iterating over the regex object, but that's not what you're doing.
To me it would make much more sense to have a simple method like
RegExp.prototype.execAll = function execAll(str) {
var res = [],
regex = this.global ? this : new RegExp(this, "g"),
matches;
while (matches = regex.exec(str))
res.push(matches);
return res;
};
String.prototype.matchAll = function(reg) { return reg.execAll(this); };
that you can call on a regex and then use arbitrary (actual) Array
methods on the result.
Greetings,
Bergi
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Recommendation for new RegExp (Array-extra-like) methods brettz9@gmail.com - 2013-08-28 07:51 -0700
Re: Recommendation for new RegExp (Array-extra-like) methods Andreas Bergmaier <andber93@web.de> - 2013-08-28 17:16 +0200
Re: Recommendation for new RegExp (Array-extra-like) methods brettz9@gmail.com - 2013-08-28 08:21 -0700
Recommendation for array-like methods on Iterator; Was Re: Recommendation for new RegExp (Array-extra-like) methods brettz9@gmail.com - 2013-08-28 16:30 -0700
Re: Recommendation for new RegExp (Array-extra-like) methods Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-08-30 16:00 +0200
Re: Recommendation for new RegExp (Array-extra-like) methods Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-09-01 15:25 +0200
csiph-web