I assume you want to add a tab only if the 85th character is a newline, or if the 85th symbol is not a newline, add both a newline and a tab.
Then, you can use @"(?s).{0,85}"
regex that will match any symbols from 0 to 85, as many as possible (it is a greedy quantifier) and check if the last character is a newline or not. Then, do what is necessary:
var str = "This is a really long test string is this is this is this is this is this is this is thisit is this this has to be way more than 85 characters ssssssssssss";
Console.WriteLine(Regex.Replace(str, @"(?s).{0,85}",
m => m.Value.EndsWith("\n") ? m.Value + "\t" : m.Value + "\n\t"));
Result of the demo:
This is a really long test string is this is this is this is this is this is this is
thisit is this this has to be way more than 85 characters ssssssssssss
If you need to only add a tab if there the 85-character match contains a newline, replace the .EndsWith("\n")
with .Contains("\n")
in the above code.
To avoid splitting in the middle of a word, add a word boundary: @"(?s).{0,85}\b"
. Or, if it is not always a word character at the end, use @"(?s).{0,85}(?!\w)"
. Another possible scenario is when you want to ensure at least 85 characters (or a bit more if the word boundary is not found), use @"(?s).{85,}?(?!\w)"
.