我想匹配(从.cs文件中选择)属性名,字段名和使用正则表达式的地方。
这是示例类:
using System;
... // usings
using Grpc.Net.Client;
using UI = Gtk.Builder.ObjectAttribute;
namespace DummyProject;
public class MainWindow : Window
{
[UI] private readonly MenuItem _aboutMenuItem;
[UI] private readonly MenuItem _openFolderItem;
[UI] private readonly MenuItem _openFileItem;
[UI] private readonly Viewport _fileViewport;
[UI] private readonly Notebook _codeNotebook;
private readonly SourceView _codeSourceView;
private readonly FileViewer _fileViewer;
private readonly Files.FilesClient _filesClient;
public FileSystemViewer FileSystemViewer { get; }
public MainWindow()
{
_fileViewer = new FileViewer();
// some code
}
// methods
结果将是:_aboutMenuItem
、_openFolderItem
、_openFileItem
、_fileViewport
、_codeNotebook
、_codeSourceView
、_fileViewer
、_filesClient
、FileSystemViewer
我试过这个正则表达式:^(?:(?=[^()]*$))?(?:(?!.*\b(namespace|return|using|class)\b))[\t \b]*(?:[\[\]a-zA-Z0-9_.]+\s+)?(?:(?:private|public|protected|internal)\s+)?(?:(?:static readonly|static|const|readonly|volatile|virtual|override)\s+)?(?:(?:[a-zA-Z0-9\.]+)\s+)?(\w+)\s*
但此正则表达式匹配不正确(请参见https://regex101.com/r/ZbctGa/3)
有什么建议吗?
1条答案
按热度按时间f8rj6qna1#
您可以使用以下命令捕获 * properties * 和 * field *。
输出量