这是我的文本文件的一部分:
[Script Info]
Title: Default Aegisub file
ScriptType: v4.00+
WrapStyle: 0
ScaledBorderAndShadow: yes
Collisions: Normal
Scroll Position: 0
Active Line: 0
Video Zoom Percent: 1
YCbCr Matrix: None
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR,MarginV, Encoding
Style: Default,Arial,20,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,2,2,10,10,10,1
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:0:03.84,0:0:07.17,Default,,0,0,0,,An Aztec temple.
Dialogue: 0,0:0:08.88,0:0:10.97,Default,,0,0,0,,Aztecs this far south?
Dialogue: 0,0:0:11.1,0:0:13.84,Default,,0,0,0,,Dr. Covas, we must stop.
This is sacred ground.
Dialogue: 0,0:0:13.88,0:0:15.85,Default,,0,0,0,,This could be the biggest
archeological discovery
Dialogue: 0,0:0:15.88,0:0:16.87,Default,,0,0,0,,of the 21st century.
我需要这样做(我跳过一些部分向你展示改变后的结果)
Dialogue: 0,0:0:03.84,0:0:07.17,Default,,0,0,0,,An Aztec temple.
Dialogue: 0,0:0:08.88,0:0:10.97,Default,,0,0,0,,Aztecs this far south?
Dialogue: 0,0:0:11.1,0:0:13.84,Default,,0,0,0,,Dr. Covas, we must stop.\NThis is sacred ground.
Dialogue: 0,0:0:13.88,0:0:15.85,Default,,0,0,0,,This could be the biggest\Narcheological discovery
Dialogue: 0,0:0:15.88,0:0:16.87,Default,,0,0,0,,of the 21st century.
我尝试过很多类似的事情:LoadedFile = Regex.Replace(LoadedFile, @"(?<=Dialogue.+)[\n\r]+^(Dialogue)", "\\N");
在单词中我想用新行替换新行 \ N 只有新行后的文字不是“对话”
答案 0 :(得分:1)
string LoadedFile = File.ReadAllText("1.txt");
string result = Regex.Replace(LoadedFile, "(Dialogue.+?)\r\n^((?!Dialogue).*)$", "$1\\N$2", RegexOptions.Multiline);