Regular Expressions Named capture groups What a named capture group looks like

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

Given the flavors, the named capture group may looks like this:

(?'name'X)
(?<name>X)
(?P<name>X)

With X being the pattern you want to capture. Let's consider the following string:

Once upon a time there was a pretty little girl...

Once upon a time there was a unicorn with an hat...

Once upon a time there was a boat with a pirate flag...

In which I want to capture the subject (in italic) of every lines. I'll use the following expression .* was a (?<subject>[\w ]+)[.]{3}.

The matching result will hold:

MATCH 1
subject    [29-47]    `pretty little girl`
MATCH 2
subject    [80-99]    `unicorn with an hat`
MATCH 3
subject    [132-155]    `boat with a pirate flag`


Got any Regular Expressions Question?