samedi 23 avril 2016

Need a regex pattern solution for use with Powershell's Get-Content replace command

I have an xml meta data file whose header I need to change. The header looks like this:

<BuildEntry xmlns:xsi="http://ift.tt/ra1lAU" xmlns:xsd="http://ift.tt/tphNwY" Name="blablaName" Version="r26" Author="blablaAuthor" Website="blablaWebsite">

The idea is to run a Get-Content replace on this file and set the version to the current build version for the project. In above case, version is r26. It can be rXX where X is any number.

I need it to change to r01 or r67 where 01 and 67 are the latest project build numbers.

My Powershell build script looks like this but does not work:

$prevVerionHeader = 'Version="((r)\d*)" Author='
$newVerionHeader = 'Version="r'+$number+'" Author='
Write-Host $prevVerionHeader
Write-Host $newVerionHeader

(Get-Content $SBmetaDataPath).replace($prevVerionHeader,$newVerionHeader) | Out-File $SBmetaDataPath

$SBmetaDataPath is the full path to the file and $number is the latest build number.

If I use the following then replace happens perfectly:

$prevVerionHeader = 'Version="r26" Author='

What I need is a regex pattern that will match against Version="rXX". I realize having rXX between double quotes may be causing problems here.

Please help. I do have some experience with Powershell but it is very intimidating and confusing. Also it's too late to change my automated build file to something other than Powershell.

Aucun commentaire:

Enregistrer un commentaire