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

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -