Reputation: 71
I am trying to match a line, and replace the trailing characters and newline with a newline, parenthesis, newline...while preserving the rest of the line.
In Sed, I would do something like:
/^thisline./s/$.\n/\n\)\n/
or? I forget, its been a while...
s/^thisline./$.\n/\n\)\n/
In order to match:
thisline: "blah etc blah",\n
and replace it with:
thisline: "blah etc blah"\n)\n
I am unfamiliar with the .Net Regex methods though. How do I implement this function in System.Text.RegularExpressions?
Upvotes: 0
Views: 88
Reputation: 72860
You should use the Regex.Replace
method (follow the link to see it in MSDN). You'll find the regular expression syntax pretty similar, and this page gives you sample code for it. Something like this:
new Regex(pattern).Replace(input, replacement);
I can't work out exactly from your post what your pattern should be, as I can't see how you are determining what constitutes "trailing". If you can be more explicit, I can give you more detail. But I suspect you can fill in the blanks yourself from your question.
Upvotes: 4