我有一个文本文件,其中包含有关录音的信息,包括曲目编号和名称,我想删除除曲目编号和曲目名称之外的所有其他文本.例如,文本文件如下所示:
text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text d1t01 - trackname d1t02 - trackname d1t03 - trackname d1t04 - trackname d1t05 - trackname d1t06 - trackname d1t07 - trackname d1t08 - trackname d1t09 - trackname d1t10 - trackname d1t11 - trackname text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
我想留下这个:
d1t01 - trackname d1t02 - trackname d1t03 - trackname d1t04 - trackname d1t05 - trackname d1t06 - trackname d1t07 - trackname d1t08 - trackname d1t09 - trackname d1t10 - trackname d1t11 - trackname
我想出了如何匹配这个正则表达式的行的开头:
d[0-9]+t[0-9]+[0-9]+ -
但我无法弄清楚如何删除“文本”的其余部分,只留下这些行.我还需要它来删除“返回”,而不是在文本文件中留下任何空白行.
谢谢!
编辑:你应该能够在这里使用以下内容.
原文链接:https://www.f2er.com/regex/356646.htmlFind: ^(?!d\w+).*\r?\n? Replace:
正则表达式:
^ the beginning of the string (?! look ahead to see if there is not: d 'd' \w+ word characters (a-z,A-Z,0-9,_) (1 or more times) ) end of look-ahead .* any character except \n (0 or more times) \r? '\r' (carriage return) (optional) \n? '\n' (newline) (optional)