0

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].

1
  • Regex [space]Version 12.3.nnnn[space] will not match your first example Version 12.3 Commented Jul 11, 2012 at 16:40

2 Answers 2

2

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 }
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.