小编Rod*_*oAP的帖子

正则表达式仅在多行匹配中

我有一个旧的应用程序,它会生成类似以下内容的内容:

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,找不到解决方案。我不想写一个应用程序来做到这一点,当然有办法......

regex perl awk sed

3
推荐指数
1
解决办法
102
查看次数

设置用作映射值的不同结构的字段的通用函数

具有具有共同字段的结构......

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)

generics dictionary interface go

2
推荐指数
1
解决办法
598
查看次数

标签 统计

awk ×1

dictionary ×1

generics ×1

go ×1

interface ×1

perl ×1

regex ×1

sed ×1