[英]How to replace special character in Linux VI Editor?
I want to remove some special characters from a file in linux using vi editor, such as我想使用 vi 编辑器从 linux 中的文件中删除一些特殊字符,例如
{
}
:
[
]
I tried below pattern but not working for all possible symbols above.我尝试了以下模式,但不适用于上述所有可能的符号。
:%s/\{//g
got an error: E866: (NFA regexp) Misplaced { E64: { follows nothing E476: Invalid command得到一个错误:E866:(NFA 正则表达式)错位 { E64:{ 没有遵循 E476:无效的命令
Overall, see :h:s
and :h pattern
.总体而言,请参见
:h:s
和:h pattern
。 See man 7 regex
.见
man 7 regex
。
\{
starts a bound in basic regular expression. \{
在基本正则表达式中开始一个界限。 vi does not really use basic regular expression, but anyway, it's like close to it. vi 并没有真正使用基本的正则表达式,但无论如何,它就像接近它一样。 You want to match character
{
, and not repeat previous pattern, so just match {
.你想匹配字符
{
,而不是重复以前的模式,所以只需匹配{
。
:%s/{//g
for all possible symbols above.
对于上述所有可能的符号。
If you want to put [
]
inside a bracket expression [...]
you have to put them as the last/first.如果要将
[
]
放在括号表达式[...]
中,则必须将它们放在最后/第一个。 So like []]
matches a single ]
, like [][]
matches [
or ]
.所以像
[]]
匹配单个]
,像[][]
匹配[
或]
。
:%s/[]{}:[]//g
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.