powershell - Extract multiple Substrings from String -


i have xlsx file contains listing of barcodes, listed 3 or 4 cell, need split have barcode.

the barcodes strings of 6 numbers, may prefaced several different letters , there may or may not commas, ampersands, , other words in cell them. looks this:

 col 1 | col 2 | col 3 | col 4 | col 5 info  | identifier | info  | info  | l123456 , pc 654321 , m 123654 & 546123 vacant | info | identifier | info | info | pc 123456 , m 456789 occupied info | identifier | info | info | l 987654 

so far have attempted use regex remove noise data , left barcodes, has been returning jumbled mess.

i need have way keep track of row came from, there identifier in earlier column needs linked these barcodes. able access identifier quite easily.

i using excel comobject manipulating sheet. code using attempt regex, how can extract barcodes?

$xl = new-object -comobject excel.application $xl.visible = $true $xl.displayalerts = $false $xl.workbooks.open("file.xls") $sheet = $xl.activeworkbook.activesheet $x = 3 3..8|%{     $uc = $sheet.range("b"+$x).text     $equip = $sheet.range("i"+$x).text     $loc = $sheet.range("d"+$x).text + '-nhq'     $uidcc = $uc.replace(" / ",",")     $tagnums = $equip -replace " [a-z]+ ",""     $tagnums = $tagnums -replace " & ",""     $tagnums = $tagnums -replace "[a-c][1-9]+",""     $tagnums = $tagnums -split ','     foreach($i in $tagnums){         $asset += $i+","+$loc+","+$uidcc+"`n"     }     $x++ } $asset | format-table $xl.quit() [system.runtime.interopservices.marshal]::releasecomobject($xl) 

if understand right need this:

$tagnums = @([regex]::matches($equip,'\d*(\d{6})')|%{$_.groups[1].value}) 

for example, input data 'l123456 , pc 654321 , m 123654 & 546123 vacant' next output:

123456 654321 123654 546123 

and 'l 987654' 987654.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -