Using a named capture groups causes a different match

Using a named capture groups causes a different match

Given Regex: ^(Start\.)?(.+?)(\.|\.\2)?(End)?$

Given Regex: ^(Start\.)?(.+?)(\.|\.\2)?(End)?$

Test Input: Start.Word.WordEnd

I get Word for Group "2":

However if I change the regex to also include a name for the captured group, I get a different result:

Regex: ^(Start\.)?(?<capturedGroup>.+?)(\.|\.\2)?(End)?$

capturedGroup is Word.Word

This is in .NET 4.7.2 (I also did the test in https://dotnetfiddle.net/ with the same result). Links:

first case: https://dotnetfiddle.net/o33G6Y

second case: https://dotnetfiddle.net/4zJuaQ

I tested this in https://regex101.com/ (set as PHP) and I get the expected result (both are Word), so I expect this to be a .NET issue? Please help.

c-sharp .net regex

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

C. C++. C#. 차이점 알려드림. 5분 순삭. Explain C.C++.C#. Like I'm Five

C. C++. C#. 차이점 알려드림. 5분 순삭. Explain C.C++.C#. Like I'm Five. 아시죠? C는 C++.C# 줄인말이 아니라는거?

Learn how to perform CRUD operations using C Sharp

QuickStart: CRUD Operations in C Sharp. Learn how to perform CRUD operations using C Sharp for MongoDB databases.

How to creating a Fluent API class in C#.NET

In this article we will look at creating a Fluent API class in C#.NET. In a Fluent API, we can link together different functionality to get a particular result. We see this used many times in Entity Framework Core and when manipulating List&lt;T&gt; type of items using lambda expressions.

Pixel Color Bot in C#, Visual Studio, .NET and WPF

Create a Pixel Color Bot in C# Visual Studio by using the .NET framework and WPF. This C# tutorial guides you through the development process of creating a pixel bot.

Loops in C++ | For, While, and Do While Loops in C++

In this Video We are going to see how to use Loops in C++. We will see How to use For, While, and Do While Loops in C++.