Radar
Radar

Reputation: 13

Replacing several sub-version numbers with another one using PowerShell

I'm have several Puppet manifests with version information about the software that my company develops. It looks something like this:

app_version     => '11.6.1',

I need to change the version number to a sub-version that just adds a letter at the end of the version number, so that it looks like this for example:

app_version     => '11.6.1d',

My manifests contain already some subversions, so you would have already some 11.6.1a. I'm using a hashtable to store the different versions and replacement values:

$versions = @{
  '11.6.1[a-zA-Z]'  = '11.6.1b';
  '11.7.0[a-zA-Z]'  = '11.7.0d';
  '11.7.2[a-zA-Z]'  = '11.7.2b';
  '11.8.6[a-zA-Z]'  = '11.8.6c';
  '11.8.13[a-zA-Z]' = '11.8.13b'
}

I'm having issues with this because using the the version number followed with [a-zA-z] will only change the subversions that contain a letter after the version number.

What expression do I need to use in $versions so that it looks at versions that are 11.6.1 OR 11.6.1 + a letter after the 1?

Upvotes: 1

Views: 41

Answers (1)

ffledgling
ffledgling

Reputation: 12150

If you're looking for a regular expression to match both 11.6.1 and 11.6.1d, you probably want:

11.6.1[a-zA-Z]?

Which optionally matches the last set ([a-zA-Z]) if it exists, but does not if it doesn't exist.

Upvotes: 1

Related Questions