This topic contains 4 replies, has 2 voices, and was last updated by
October 16, 2014 at 10:25 am #19765
I have a script that's supposed to change a value in a file on multiple servers
it works and all, but as I would like to understand and learn what each part does(99.9 % i do)
I cannot understand what this little $ sign does and why do I need it:
-replace 'MaxActiveMovesPerSourceMDB = "5"$','MaxActiveMovesPerSourceMDB = "50"' `
why do I need the $ sign before I close the value i want to replace with a ' ?
replace 'MaxActiveMovesPerSourceMDB = "5"$',
October 16, 2014 at 10:27 am #19767MemberPoints: 0Rank: Member
PowerShell's -replace operator uses regular expressions for its first argument. In a regex, the $ character means to only match the pattern at the end of the string (or at the end of a line, depending on how you're using it.) There's an about_Regular_Expressions help file in PowerShell that can help you get started with that.
October 16, 2014 at 10:33 am #19769
Thanks for a blazing fast reply:)
I only saw one documentation of this '$ sign but I wasn't sure if it even fits what I see here cause I got some value enclosed with 'value1' to replace with another value 'value2'
in my case I think im replacing/matching whatever is inside these ' ' so that's why I don't understand why this $ is needed:)
but maybe its just faster this way it match "end characters instead of the whole value?
I wonder what "end character mean anyway:)? 1?3? or just from the end to start whatever matches?
sorry for the many questions
October 16, 2014 at 10:37 am #19772MemberPoints: 0Rank: Member
Well, say that your string varialbe contained this:
$string = "cat dog cat dog cat dog"
You can see the difference between using the $ in the pattern or not:
$string -replace 'dog', 'zebra' # This replaces all 3 instances of "dog" $string -replace 'dog$', 'zebra' # This replaces only the word "dog" at the very end of the string.
October 16, 2014 at 12:05 pm #19778
Thanks a million
The topic ‘'$ quick question’ is closed to new replies.