Search⌘ K

Special Characters: Capturing and Non-Capturing Groups

Explore the difference between capturing and non-capturing groups in JavaScript regular expressions. Understand how to capture specific parts of a match for reuse or organize patterns without capturing. Learn to apply these groups to extract hostnames from URLs, enhancing your pattern building and data parsing skills.

We'll cover the following...

Introduction

Groups are an incredibly useful part of regular expressions because they allow you to grab a portion of the matching pattern and use it in your code logic or reference it while doing a string replacement.

The groups you can grab and reference later are called capturing groups, which, as the name suggests, means you’re able ...