Create Capture Groups in Regular Expressions

InstructorJoe Maddalone

Share this video with your friends

Send Tweet

In this lesson we'll capture groups of characters we wish to match, use quantifiers with those groups, and use references to those groups in String.prototype.replace.

Piyush
~ 8 years ago

I did not understand the application of ?: (non capturing of the capture group). When would I use this optimization?

Joe Maddaloneinstructor
~ 8 years ago

As explained in the lesson, if you wanted to trim back on the memory allocated for storing the reference to the group you'd opt out. Perhaps you only wanted to utilize the alternation functionality, but did not need to reference the group later as expressed in something like:

var regex = /www\.google\.(?:com|net|org)/ regex.test('www.google.net') //true regex.test('www.google.edu') //false