I want to remove some special characters from a file in linux using vi editor, such as
{
}
:
[
]
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
Overall, see :h:s
and :h pattern
. See 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. 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.