regex - Regular expression pattern to allow digit and asterisk -
how can last 4 digits in $mybuildnumber, asterisk? want $newversion return "2.8.1.*"; however, code not return me:
$mybuildnumber = "mybuildnumberis_2.8.1.*" $versionregex = "\d+[*]?\.\d+[*]?\.\d+[*]?\.\d+[*]?" $versiondata = [regex]::matches($mybuildnumber,$versionregex) switch($versiondata.count) { 0 { write-error "could not find version number data in mybuildnumber." exit 1 } 1 {} } $newversion = $versiondata[0] write-host "version: $newversion"
you can use character class digit , *
:
[\d*]+\.[\d*]+\.[\d*]+\.[\d*]+
Comments
Post a Comment