Yes - I can see from both yours and Peter van der Zee's replies that "exec in a 
loop" is a much better way of going.

Thanks!

Pete


On 23 Oct 2011, at 12:52, Lasse Reichstein wrote:

> On Sun, Oct 23, 2011 at 1:40 PM, pete otaqui <[email protected]> wrote:
>> 
>> I wasn't really asking a question so much as noting down a useful 
>> observation I'd made.
>> 
>> As you can see from my examples, it's not just the matches from the global 
>> RegExp that I'm after, it's also the sub patterns.  These are never returned 
>> by anything when using a global RegExp.
> 
> They are returned by RegExp.prototype.exec, and they are available if
> you use String.prototype.replace or String.prototype.split.
> If you need to access them, you can just to use .exec in a loop.
> 
> String methods like String.prototype.match are not the most basic
> operation on a RegExp, and it does indeed not return the captures when
> used with a global regexp.
> 
> Personally, I rarely, if ever, use String.prototype.match for anything.
> 
>> My message was just about a technique which actually uses .replace with a 
>> callback rather than .match as a way of getting everything about each 
>> capture (including lastIndex, and all the sub patterns).
> 
> That's another way to do it, but it's rather wasteful, since you build
> the result of .replace without actually needing it.
> /L
> 
> -- 
> To view archived discussions from the original JSMentors Mailman list: 
> http://www.mail-archive.com/[email protected]/
> 
> To search via a non-Google archive, visit here: 
> http://www.mail-archive.com/[email protected]/
> 
> To unsubscribe from this group, send email to
> [email protected]

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to