Complicated problem. Need help with regular expression replace

frankm

New Member
I'm in the process of updating a program that fixes subtitles. Till now I got away without using regular expressions, but the last problem that has come up might benefit by their use. (I've already solved it without regular expressions, but it's a very unoptimized method that slows my program significantly).TL;DR;I'm trying to make the following work:I want all instances of:
\[code\]"! ."\[/code\] , \[code\]"!."\[/code\] and \[code\]"! . "\[/code\] to become: \[code\]"!"\[/code\] unless the dot is followed by another dot, in which case I want all instances of:
\[code\]"!.."\[/code\] , \[code\]"! .."\[/code\] , \[code\]"! . . "\[/code\] and \[code\]"!. ."\[/code\] to become: \[code\]"!..."\[/code\]I've tried this code: \[code\]the_str = Regex.Replace(the_str, "\\! \\. [^.]", "\\! [^.]");\[/code\]that comes close to the first part of what I want to do, but I can't make the \[code\][^.]\[/code\] character of the replacement string to be the same character as the one in the original string... Please help!I'm interested in both C# and PHP implementations...
 
Back
Top