I have this script that does some regex replace on file. What I don't understand is why the returned string has all its newline removed?
Sample file content (UTF-8, with CR-LF after each line):
hello
hello
hello
The script:
$content = Get-Content "c:\spikes\regexnewline\regexnewline.txt"
Set-Content "c:\spikes\regexnewline\regexnewline-2.txt" $content # test
$content = [regex]::Replace($content, "ll", "yy") #basic replace
Set-Content "c:\spikes\regexnewline\regexnewline-3.txt" $content
Of course, file regexnewline-2.txt is an exact copy of the input file. But how come regexnewline-3.txt has its content on one line only, with a single CR-LF at the end?
heyyo heyyo heyyo\CR\LF
Obviously I'm missing something here. Can anyone spot it?
BTW, I've tried to play with regex.Replace and use the overload with 4 arguments, specifying RegexOptions, as documented on MSDN, but the script fails saying there's no 4-argument overload for this method. Is Powershell using a different version of the .Net framework?
$contentto the command line just before putting it to the file, what do you see ?