首页 文章

在VI编辑器中替换与特定表达式匹配的正则表达式的每个出现位置?

提问于
浏览
-3

假设我有一个文本文件如下 .

create table "kevin".tb1 {
col1,
col2
}
create table "jhone".tb2 {
col1,
col2
}
create table "jake".tb3 {
col1,
col2

}

我需要通过替换每个表所有者名称occernces raplace以及名为“informix”的相同名称来获取该文本文件 .

出来应该是这样的

create table "informix".tb1 {
col1,
col2
}
create table "informix".tb2 {
col1,
col2
}
create table "informix".tb3 {
col1,
col2
}

在vi编辑器中,

:%S / “凯文”/ “的Informix”/克

我可以单独替换它们,但我需要立即完成所有这些操作 .

1 回答

  • 0
    %s/\(create table\) "\i\+"/\1 "informix"/
    

    说明:

    % — run through every line in the file
    s/ — search and replace
    \(create table\) — match the text and store it in the backreference 1
    "\i\+" — match any number (more than 1) of identifier characters inside double quotes
    \1 "informix" — replace what is found with backreference 1 (text "create table"), a space and text "informix"
    

相关问题