开发者

Regex to remove chords from a text file

I have a big file (about 20k lines) of music with chords.

I'm trying to make a program to remove the chords from my file.

My regex to find chords is:

Regex regex = new Regex("([A-G](#|b)*([a-z]|[0-9])*)(/[A-G](#|b)*([a-z]|[0-9])*)*开发者_Go百科");

The problem is a logical problem.

How do I detect if a line of my text have only chords using my regex?

UPDATE: Sample of the file:

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! 


You can anchor your regex by wrapping it in ^...$.
This will force it to match entire lines.

You can then loop through File.ReadLines, like this:

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


How about this:

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

This will remove all lines that contain only the letters A through G, #, b, /, - or whitespace.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜