本帖最后由 5i365 于 2022-9-30 09:36 编辑
已经解决:- $dd = @"
- Chapter 1. A
- Chapter 2. b
- Chapter 9. e
- Chapter 10. f
- Chapter 16. g
- "@
-
- $dd -split '\n' |
- %{
- if ($_ -match '.+\s+(\d{1,2})\.\s+(.+)')
- {
- $n = '{0:d2}' -f [int]$matches[1]
- '{0} {1}' -f $n, $matches[2]
- }
- }
复制代码
或者:
- $dd = @"
- Chapter 1. A
- Chapter 2. b
- Chapter 9. e
- Chapter 10. f
- Chapter 16. g
- "@
-
- $dd -split '\n' |
- %{
- if ($_ -match '.+\s+(\d{1,2})\.\s+(.+)')
- {
- '{0} {1}' -f $matches[1].padleft(2, '0'), $matches[2]
- }
- }
复制代码
|