我有一个旧的应用程序,它会生成类似以下内容的内容:
USERLIST (
"jasonr"
"jameso"
"tommyx"
)
ROLELIST (
"op"
"admin"
"ro"
)
Run Code Online (Sandbox Code Playgroud)
我需要某种形式的正则表达式,仅将USERLIST部分更改为USERLIST("jasonr", "jameso", "tommyx"),其余文本保持不变:
USERLIST("jasonr", "jameso", "tommyx")
ROLELIST (
"op"
"admin"
"ro"
)
Run Code Online (Sandbox Code Playgroud)
除了多行问题之外,我不知道如何处理仅部分字符串的替换。我尝试过perl( -0pe)和sed,找不到解决方案。我不想写一个应用程序来做到这一点,当然有办法......
具有具有共同字段的结构......
type Definition struct {
Id string
...
}
type Requirement struct {
Id string
...
}
type Campaign struct {
Id string
...
}
Run Code Online (Sandbox Code Playgroud)
...我有多个这样的函数:
func fillDefinitionIds(values *map[string]Definition) {
for key, value:=range *values { // Repeated code
value.Id=key // Repeated code
(*values)[key]=value // Repeated code
} // Repeated code
}
func fillRequirementIds(values *map[string]Requirement) {
for key, value:=range *values { // Repeated code
value.Id=key // Repeated code
(*values)[key]=value // Repeated code
} // Repeated code
}
func fillCampaignIds(values *map[string]Campaign) { …Run Code Online (Sandbox Code Playgroud)