搜索和替换“(”“”和“[”Vi - Regex

时间:2012-01-27 22:57:59

标签: regex linux vi

我有这一行:

[app_user] ([id], [nome], [email], [login], [senha], [tipo], [data]) 

我想替换它:

(id, name, email_address, username, password, access_type, created)

我是怎么做到的?
我试试这个(在vi中):

:%s/\[app_user\] \+\\( \[id\], \+\[nome\], \+\[email\], \+\[login\], \+\[senha\], \+\[tipo\], \+\[data\]\\) /\\( id,name,email_address,username,password,access_type\\)/

但没效果。

我认为问题出现在“\ + //(”,因为我尝试运行,只有简单搜索:

/\[app_user\] \+

并且有效 我不是Regex的专家。

1 个答案:

答案 0 :(得分:2)

要禁用搜索模式中除反斜杠之外的所有特殊字符,请使用\V(非常无害),这样可以更轻松地编写它:

:%s/\V[app_user] ([id], [nome], [email], [login], [senha], [tipo], [data])/(id, name, email_address, username, password, access_type, created)