Regular Expressions What a named capture group looks like


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`