What's wrong with my REGEX while using VI editor?
I have a text document like so:
&开发者_如何学JAVAlt;table width="10">
</table>
I open the document with the VI editor. I want to replace all instances of width="somenumber" with nothing. I issue this command in the VI editor:
:0,$s/width="[\d]+"//gc
VI says no pattern found. I also tried this and it doens't work:
0,$s/width="[0-9]+"//gc
This one below worked:
:0,$s/width="\d\d"//gc
What's wrong with my first two expressions?
You have two errors in your regexp!
First, use \d
without []
s around it. You probably mix it with character classes like :alpha:
, :digit:
, etc.
Second, Escape the +
sign. By default you should escape it.
So your regexp would be:
:0,$s/width="\d\+"//gc
And, please, read help before posting on stackoverflow:
:h :s
You may also be interested in this help section:
:h magic
You want:
:0,$s/ width="\d\+"//gc
\d
isn't recognized inside a character class (or rather, it's recognized as the letter d
), and +
without a backslash isn't recognized as a metacharacter by vim
's BRE. You also probably want the space before width
to be eliminated.
It will only work with widths of two digits, won't it?
精彩评论