1
1
1rayman12021-12-13 11:49:52
PowerShell
1rayman1, 2021-12-13 11:49:52

Powershell how to replace last 2 characters in each word?

Please help me, I have a variable that contains a full name in the form "Ivanov Ivan Ivanovich", I can't figure out how to replace the last 2 characters of each word with * due to poor knowledge of the language, so that in the end it would turn out like this "Ivan* Ivan* Ivanov*

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MaxKozlov, 2021-12-13
@1rayman1

"Иванов Иван Иванович" -replace '\w{2}(\s|$)','*$1'

Ivan* Iv* Ivanov*

V
Vladimir Yurchenkov, 2021-12-13
@EPIDEMIASH

First, split your variable into an array, change it through replace, and reassemble it into a string.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question