我在 markdown 中有一个文档,我想为每个城市条目添加一个自定义 ID。文档的基本布局如下:
#Country
## StateA
### CityA
#### Population
#### Government
#### History
### CityB
#### Population
#### Government
#### History
## StateB
### CityA
#### Population
#### Government
#### History
### CityB
#### Population
#### Government
#### History
对于每个城市,我想添加一个带有计数器的自定义 ID。例如,ID 看起来像:
#USA
## FL
### US_FL_00001
### US_FL_00002
### US_FL_00003
## GA
### US_GA_00001
### US_GA_00002
### US_GA_00003
我知道使用正则表达式来选择城市相对简单,使用 re.findall() 和 re.sub() 作为 '###' 标题,但我怎样才能拉入状态和 ID 的连续计数器?