oz888 oz888 - 1 year ago 132
PowerShell Question

Powershell - replace string in file with wildcards

I have a file that includes the following text:

this is a testVersion= test test

I am trying to update the Version= using Powershell v2 to become Version= using -replace
The version numbers are random, so this would need to account for an unknown version number but the format will always be the same with the word Version, an equals sign, and alternating digit, period, digit, period, digit, period, digit for the version number. As you can see, there is other text to the left and the right of the Version= as well, and that needs to stay where it is without being affected. After changing the version number, i need to write these changes to a new file. Any help would be greatly appreciated! Thanks

Answer Source

An incomplete example that should be PS 2 compatible.

'Version=' -replace '(\d+)\.(\d+)\.(\d+)\.(\d+)', '$4.$3.$2.$1'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download