We have customers that do not mention our INV-prefix when they pay invoices so I want to add it to our MT940-bank statement file.
:20: :25:MHAZNL2AXXX/0376603160 :28C:102/ :60F:C220525EUR5000,
:61:2204130413C336,52NMSCTOPF2500472627//GBBR001SCT TOPF2500472627
:86:17136 17364 17382 032022102402 WONG TONG SARL 1 RUESOMETHINGPARIS SOGEFRPPXXX NOT PROVIDED
:61:2204200420C406,02NMSCTOPF2500479378//GBCJ005SCT TOPF2500479378
:86:17486 17586 17697 17813 0320221054201 WONG TONG SARL 1RUE SOMETHINGPARIS SOGEFRPPXXX NOTPROVIDED
I need it to be
:20: :25:MHAZNL2AXXX/0376603160 :28C:102/ :60F:C220525EUR5000,
:61:2204130413C336,52NMSCTOPF2500472627//GBBR001SCT TOPF2500472627
:86:INV17136 INV17364 INV17382 032022102402 WONG TONG SARL 1 RUESOMETHINGPARIS SOGEFRPPXXX NOT PROVIDED
:61:2204200420C406,02NMSCTOPF2500479378//GBCJ005SCT TOPF2500479378
:86:INV17486 INV17586 INV17697 INV17813 0320221054201 WONG TONG SARL 1RUE SOMETHINGPARIS SOGEFRPPXXX NOTPROVIDED
I use a switch statement to match other lines as well that is why I use switch.
switch -Regex -File c:\Temp\WONG.ged {
':86:.+WONG TONG.+' { $_.replace('([1234567]\d{4}[ ])', "INV$1") }
default { $_ } # unrelated line, pass through
}
This seems to work but the replace does not work (if I replace eg. WONG for TEST then it works fine). I added 1234567 to prevent it from matching too much but it still matches too much.
.replace( )doesnt know what regex is, you probably wanted to use-replace'INV$1'or"INV`$1"WING SENG, there isWONG TONG(Get-Content $filepath) -replace '(\G(?!^)|^(?=:86:.+WONG TONG))(.*?)([1234567]\d{4}(?!\S))', '$1$2INV$3'