Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 正则表达式从文本文件中删除和弦_C#_Regex_Logic - Fatal编程技术网

C# 正则表达式从文本文件中删除和弦

C# 正则表达式从文本文件中删除和弦,c#,regex,logic,C#,Regex,Logic,我有一个大文件(约20k行)的和弦音乐 我正在尝试制作一个程序来删除我文件中的和弦 我找到和弦的正则表达式是: Regex regex = new Regex("([A-G](#|b)*([a-z]|[0-9])*)(/[A-G](#|b)*([a-z]|[0-9])*)*"); 这个问题是一个逻辑问题 如何使用正则表达式检测文本中的一行是否只有和弦 更新: 文件示例: C G Justo é o Senhor em s

我有一个大文件(约20k行)的和弦音乐

我正在尝试制作一个程序来删除我文件中的和弦

我找到和弦的正则表达式是:

Regex regex = new Regex("([A-G](#|b)*([a-z]|[0-9])*)(/[A-G](#|b)*([a-z]|[0-9])*)*");
这个问题是一个逻辑问题

如何使用正则表达式检测文本中的一行是否只有和弦

更新: 文件示例:

C                                     G 
Justo é o Senhor em seus santos caminhos, 
A -             G/B C     D4 D G 
Benigno em todas  as  suas  obras.  (bis) 
G          C          C7 
Perto está  o Senhor, (perto está dos que o invocam,) 
     F   C  D -   G  C               F        G         C F  
De todos que o invocam  (De todos que o invocam) 
C/G G   C                        F C 
Em   verdade. Aleluia! Aleluia! 

您可以通过将正则表达式包装在
^…$
中来锚定它
这将迫使它匹配整条线

然后可以循环浏览
文件.ReadLines
,如下所示:

var nonChords = File.ReadLines(path)
                    .Where(s => !regex.IsMatch(s));

您可以通过将正则表达式包装在
^…$
中来锚定它
这将迫使它匹配整条线

然后可以循环浏览
文件.ReadLines
,如下所示:

var nonChords = File.ReadLines(path)
                    .Where(s => !regex.IsMatch(s));
这个怎么样:

resultString = Regex.Replace(subjectString, @"^[A-G\d#b\s/-]*$(?:\r\n)?", "", RegexOptions.Multiline);
这将删除所有只包含字母A到G、
b
/
-
或空格的行。

这是怎么回事:

resultString = Regex.Replace(subjectString, @"^[A-G\d#b\s/-]*$(?:\r\n)?", "", RegexOptions.Multiline);

这将删除所有仅包含字母A到G、
#
b
/
-
或空格的行。

能否提供该文件的示例。就几行?为什么是小写字母?它们将不带穿孔的线条。你能提供一个文件的例子吗。就几行?为什么是小写字母?我有这样的行:cfcfgc,如果我把^和$放进去,它就永远找不到“chordline”@Renanlf:你可以修改正则表达式以匹配多个和弦:
@((…)+\s*)+$”
。我有这样的行:cfgc,如果我把^和$,它永远找不到“和弦线”@Renanlf:您可以修改正则表达式以匹配多个和弦:
@“^((…)+\s*)+$”