我正在尝试替换文件中包含特殊字符和文本的部分,但是正则表达式无法正常工作。
Regexp在其他正则表达式引擎中的工作方式应类似于(\e&l8D\n)+\f$
:
[System.IO.File]::ReadAllText(
"C:\tmp\text.prn",
[System.Text.Encoding]::GetEncoding('cp866')
)
-replace '('+[char]0x001b+'&l8D'+"`n"+')+'+"`f",''
文件的一部分:
&l8D│ N18-10│ │30/07 │31/07 16:00│20:30│ │ &l8DL-------+-----------+-----------+-----------+-----+---------------------------- &l8D &l8D&l16D(3R(s1p14v0s3b4101T(s3B (s0B(s0S(3R(s0p10.00h12.0v0s0b3T: (s3B(3R(s1p16v0s3b4101T 1.030(s0B(3R(s0p10.00h12.0v0s0b3T - (s3B(3R(s1p16v0s3b4101T 1.063(s0B(3R(s0p10.00h12.0v0s0b3T .(s3B(s0B(s3B &l8D(s0B &l8D &l8D &l8D &l8D &l8D
is ESC symbol (ASCII 1B), and last
符号为FF(ASCII 0C)
预期结果:
&l8D│ N18-10│ │30/07 │31/07 16:00│20:30│ │ &l8DL-------+-----------+-----------+-----------+-----+---------------------------- &l8D &l8D&l16D(3R(s1p14v0s3b4101T(s3B (s0B(s0S(3R(s0p10.00h12.0v0s0b3T: (s3B(3R(s1p16v0s3b4101T 1.030(s0B(3R(s0p10.00h12.0v0s0b3T - (s3B(3R(s1p16v0s3b4101T 1.063(s0B(3R(s0p10.00h12.0v0s0b3T .(s3B(s0B(s3B &l8D(s0B