Regex is still a new concept to me, but I had a piece of code that troubled me because I spent a while trying to figure out how to format decimals correctly with -replace in order to shave some extra decimal points. This is the original list I was working with:
1.20
1.150000
1.10
1.10
1.000000
1.00
1.00
0.90
0.90
Playing around with http://regexr.com/, I managed this regex: (\.\d{2})(\d{4})
with a replace value of $1, which resulted in:
1.20
1.15
1.10
1.10
1.00
1.00
1.00
0.90
0.90
This is exactly what I wanted, but I don't understand why the regex worked or whether it is the cleanest solution. According to regexr, both capture groups highlighted the two numbers with the extra decimal places from '.' onwards. Capture group #1 would've highlighted the decimal and the first two decimal places of every number on the list while #2 would've highlighted the first 4 decimals minus the '.' in the two outlier numbers. I'm not sure how specifying capture group 1 resulted in the clean list, however.
Could someone explain how this regex with -replace functioned and whether or not this was the cleanest solution? Thanks!