Post by Jürgen ExnerOn Tue, 23 Dec 2014 10:32:55 -0800 (PST), Armando Torres
Post by Armando Torres12_
123_
1_
I am using the following and it does not work; any help is appreciated.
(get-content D:\Temp\Test1.txt) | foreach-object {$_ -replace '*_', ' '} | set-content D:\Temp\Test1.txt
Your RE '*_' is wrong. The star '*' is a multiplier, so you are trying
to match zero or more instances of nothing which are then followed by
the underscore character.
You need to specify the basic item of which you would like to match zero
or more instances, e.g. any character ('.*_') or digits ('\d*_') or
whatever it is you want matched.
jue
In below examples i did not replace with a space ' ', but with a '.'
(this makes it hopefully more readable)
PS C:\temp> (get-content C:\Temp\Test1.txt) | foreach-object {$_
-replace '\d*_', '.'}
.
.
.
PS C:\temp> (get-content C:\Temp\Test1.txt) | foreach-object {$_
-replace '\d*', '.'}
.._.
.._. .
.._.
PS C:\temp> (get-content C:\Temp\Test1.txt) | foreach-object {$_
-replace '\d[^_]*', '.'}
._
._
._
The '\d*_' variant also replaces the '_'.
I do not understand the output of the second variant '\d*'
My input file is form the original post like this:
PS C:\temp> type test1.txt
12_
123_
1_
PS C:\temp>