1

This is a part of my text file:

[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.

I need to make it like that (I skipped some part to show you the changed result)

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.

I tried a lot of things like: LoadedFile = Regex.Replace(LoadedFile, @"(?<=Dialogue.+)[\n\r]+^(Dialogue)", "\\N");

In words I want to replace the new line with \N only if text after new line is not "Dialogue"

1 Answer 1

1
string LoadedFile = File.ReadAllText("1.txt");
string result = Regex.Replace(LoadedFile, "(Dialogue.+?)\r\n^((?!Dialogue).*)$", "$1\\N$2", RegexOptions.Multiline);
Sign up to request clarification or add additional context in comments.

6 Comments

Where to put that regex? Can you edit your answer with my code example?
Its not giving the result that I need
Instead of Dialogue: 0,0:0:11.1,0:0:13.84,Default,,0,0,0,,Dr. Covas, we must stop.\NThis is sacred ground. it gives Dialogue: 0,0:0:11.1,0:0:13.84,Default,,0,0,0,,Dr. Covas, we must stop.
@Loclip ah now I understand. Edited.
Its almost working... only problem its put some times "\N" where not needed for example Dialogue: 0,0:0:03.84,0:0:07.17,Default,,0,0,0,,An Aztec temple.\N
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.