pondigi
pondigi

Reputation: 906

PowerShell Regex to find " Version 12.3 "

In a string such as:

CustomerDisplayVersionNumber : Version 12.3 (build 567.89)

How can I, using a regex, return true if the version number is exactly 12.3

There is the slight, but real possibility that the version number might contain a service pack version. For example

CustomerDisplayVersionNumber : Version 12.3.4 (build 567.89)

Which leads me to believe it will be safer to check for [space]Version 12.3.nnnn[space].

Upvotes: 0

Views: 934

Answers (2)

Akim
Akim

Reputation: 8669

Regex "\sVersion (\d+\.\d+(\.\d+)?)\s" will satisfy all provided examples

 @('CustomerDisplayVersionNumber : Version 12.3 (build 567.89)', 'CustomerDisplayVersionNumber : Version 12.3.4 (build 567.89)', 'CustomerDisplayVersionNumber : Version 12.3.9999 (build 567.89)') | % { [regex]::Match($_, "\sVersion (\d+\.\d+(\.\d+)?)\s").Success }

Upvotes: 2

burning_LEGION
burning_LEGION

Reputation: 13450

use this regex \s+Version \d+\.\d+\.\d+\s+

Upvotes: 1

Related Questions