I am trying to parse through a text file with regex finding percentages as strings and replacing the findings with the percentage multiplied by a user supplied integer. If the user inputs 400, then the code should return "120 x 8, 180 x 6, etc"
Tried doing a replace but it replaces all findings with the same string.
$body = "30% x 8, 45% x 6, 55% x 4, 60% x 2, 65% x 1, 70% x 1, 75% x 1, 80% x 1, 72.5% x 4, 70% x 4, 67.5% x 4, 65% x 4"
$regex1 = "(\d+(\.\d+)?%)"
$regex2 = "(\d+(\.\d+)?)"
$regex3 = "\bx \d{0,2}\b"
$regex4 = "\b% x \d{0,2}\b"
$percent = $body | select-string -Pattern $regex1 -AllMatches | % { $_.Matches } | % { [string]$_.Value } | % {"$_,"}
$reps = $body | select-string -Pattern $regex4 -AllMatches | % { $_.Matches } | % { $_.Value } | % {"$_,"}
$weights = $body | select-string -Pattern $regex1 -AllMatches | % { $_.Matches } | % { $_.Value } | select-string -Pattern $regex2 -AllMatches | % { $_.Matches } | % { ([int]$_.Value / 100) }
$reps_percent = $body | select-string -Pattern $regex4 -AllMatches | % { $_.Matches } | % { [string]$_.Value } |select-string -Pattern $regex3 -AllMatches | % { $_.Matches } | % { [string]$_.Value } | % {"$_"}
User inputs: 400 Output: "120 x 8, 180 x 6, etc"