PowerShell, RegEx: Optional Entries - how? -


how can detect in line optional fields?

    $l = "prg=powershell°v=2.0°dtd=20120602°user=kjuz°pwd=jhiuz°chk=876876°dep=lab1°floor=4°"     $found = $l -match '(?=.*?°dtd=(\d+))(?=.*?°user=(.+?)°)(?=.*?°chk=(.+?)°).*' 

all fileds in -match must exist otherwise $found = $false. how can detect optional fields >dep=lab1< , >floor=4< may there , need values? there 'one-line' solution again order of fields varies, not fix?

thanks in advance
gooly

how divide , conquer approach instead? spit string, ° character seems field separator. is,

$ll = $l.split('°') 

now got array can filtered -match operator so,

$ll -match "(floor)|(user)" # output: user=kjuz floor=4 

by filtering splitted string, can quite work forward without complex , hard maintain regex tries match whole pattern on 1 bite.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -