Tag: 匹配

c#regex – 从类文件(.cs)中选择类属性名称,方法名称和字段

我想匹配(从类文件中选择)methodsname,属性名称和字段名称。 这是示例类: class Perl { string _name; public string Name { get; set; } public Perl() { // Assign this._name this._name = “Perl”; // Assign _name _name = “Sam”; // The two forms reference the same field. Console.WriteLine(this._name); Console.WriteLine(_name); } public static string doSomething(string test) { bla test; } } 我得到了方法的代码: (?:public|private|protected)([\s\w]*)\s+(\w+)\s*\(\s*(?:\w+\s+(\w+)\s*,?\s*)+\) 我有问题: 以上正则表达式代码获取所有方法,它工作得很好,但我也希望它选择方法名称,但没有参数和访问器。 所以从exaplmce类使用我的代码结果将是: […]

什么是可以匹配非零浮点数与任意小数位数的最短正则表达式?

什么是可以匹配非零浮点数与任意小数位数的最短正则表达式? 它应该接受像这样的数字 -1 -5.9652 -7.00002 -0.8 -0.0500 -0.58000 0.01 0.000005 0.9900 5 7.5 7.005 但拒绝诸如此类的结构 . .02 -. -.996 0 -0 0. -0. -0.000 0.00 — .. + +0 +1 +. +1.26 ,etc 我不需要支持科学记数法,e,E等。 顺便说一句,我使用的语言是C#。

在c#中使用Linq匹配2个集合之间的元素

我有一个关于如何在linq中执行常见编程任务的问题。 假设我们已经做了不同的集合或数组。 我想做的是匹配数组之间的元素,如果有匹配,那么用该元素做一些事情。 例如: string[] collection1 = new string[] { “1”, “7”, “4” }; string[] collection2 = new string[] { “6”, “1”, “7” }; foreach (string str1 in collection1) { foreach (string str2 in collection2) { if (str1 == str2) { // DO SOMETHING EXCITING/// } } } 这显然可以使用上面的代码完成,但我想知道是否有一个快速和简洁的方法,你可以用LinqtoObjects做到这一点? 谢谢!

匹配大文本文件中的字符串?

我有一个字符串列表,其中包含大小为152MB的文本文件中的大约700万个项目。 我想知道什么是实现一个带有单个字符串的函数的最佳方法,并返回它是否在该字符串列表中。

获取与其中的动态数字之间的值

我正在研究一种文本摘要方法,为了测试我的方法我有一个名为doc 2007的基准测试,在这个基准测试中我有很多xml文件,我应该清除那个文件。 例如,我有一个像这样的xml文件: The nature of the proceeding 1 The principal issue in this proceeding is whether the Victorian Arts Centre falls within the category of ‘premises of State Government Departments and Instrumentalities’, for the purposes of provisions in industrial awards relating to rates of payment for persons employed in cleaning those premises. In turn, […]

如何使用Regex在c#中的文本字符串中提取方括号的内容

如果我有一个如下所示的文本字符串,我怎样才能收集c#中集合中括号的内容,即使它超过了换行符? 例如… string s = “test [4df] test [5yu] test [6nf]”; 应该给我.. 集合[0] = 4df 集合[1] = 5yu 集合[2] = 6nf

近似字符串匹配

我知道这个问题已被问了很多时间。 我想要一个关于哪种算法适合近似字符串匹配的建议。 该应用程序专门用于公司名称匹配,而不是其他任何内容。 最大的挑战可能是公司的名称部分和简短的命名部分示例:1。companyA pty ltd vs companyA pty。 LTD。 vs companyA 2. WES工程与WES工程(极为罕见) 你认为Levenshtein编辑距离是否足够? 我正在使用C# 此致,Max

在C#中搜索字节数组中的最长模式

我需要编写有效且快速的方法来搜索给定模式的字节数组。 我这样写,你怎么想,怎么改进? 它有一个bug,它不能返回长度为1的匹配。 public static bool SearchByteByByte(byte[] bytes, byte[] pattern) { bool found = false; int matchedBytes = 0; for (int i = 0; i = pattern.Length) { for (int j = 1; j < pattern.Length; j++) { if (bytes[i + j] == pattern[j]) { matchedBytes++; if (matchedBytes == pattern.Length – 1) { return true; […]