[英]Replace new line regex with a string
這是我的文本文件的一部分:
[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替換換行
string LoadedFile = File.ReadAllText("1.txt");
string result = Regex.Replace(LoadedFile, "(Dialogue.+?)\r\n^((?!Dialogue).*)$", "$1\\N$2", RegexOptions.Multiline);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.