Regex Not Matching Multi-Line Comments in C# - Handling Edge Cases in Documented Code
I'm relatively new to this, so bear with me. I need some guidance on I'm working on a project and hit a roadblock... I'm stuck on something that should probably be simple... I'm working on a C# application where I need to parse code comments, specifically to extract multi-line comments that are formatted as `/* comment here */`. However, I'm working with issues with the regex pattern that I wrote, which seems to unexpected result when handling comments that are split across multiple lines. My current regex pattern is: ```csharp string pattern = @"/\*.*?\*/"; ``` When I run this against a string that has a multi-line comment, such as: ```csharp string code = "public class Test { /* This is a multi-line comment */ int x; }"; ``` I expect it to match the whole comment, but it only returns the first line. I also tried enabling single-line mode by using `RegexOptions.Singleline`, but I still encounter issues. The output I get is just `/* This is a`, missing the rest of the comment completely. I've also attempted using a more complex pattern like: ```csharp string pattern = @"/\*([^*]|\*+[^*/])\*+/"; ``` This doesn't seem to work either, as it leads to a `ArgumentException` due to an invalid pattern. My goal is to reliably extract the full multi-line comments without losing any part of the text. Could anyone suggest a working regex pattern or best practices for handling this in C#? Iām using .NET 5.0 and appreciate any help on this edge case. I'm working on a CLI tool that needs to handle this. I'm working in a Windows 11 environment. I recently upgraded to C# 3.11. I'd love to hear your thoughts on this. For context: I'm using C# on Windows 10.