Reputation: 906
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
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