我有几个需要格式化的类。我需要将 using 指令放在命名空间内。换句话说,我必须改变:
// some comment about system
using System;
using System.Collections.Generics; // needed to create lists
namespace MyNamespace
{
... code
进入:
namespace MyNamespace
{
// some comment about system
using System;
using System.Collections.Generics; // needed to create lists
... code
所以简而言之,我希望能够匹配:
// some comment about system
using System;
using System.Collections.Generics; // needed to create lists
到目前为止我所做的是这个正则表达式:(?s)(//.*?(?=\r))(\r\n|^)*using .*?;
第一组(//.*?(?=\r))(\r\n|^)
匹配评论。因此,如果用户有评论,我也愿意接受该评论。请注意,我*
在组的末尾放置了一个 0 或更多评论。由于某种原因,第二次使用不匹配,为什么?