I am opening a document usin...">

What happened to my REGEX when using the VI editor?

I have a text document:

<table width="10">
</table>

      

I am opening a document using 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 template found. I've also tried this and it doesn't work:

0,$s/width="[0-9]+"//gc

      

Below is the following:

:0,$s/width="\d\d"//gc

      

What happened to my first two expressions?

+2


source to share


3 answers


There are two in your regexp !

Use \d

without []

around it first. You are probably confusing it with character classes like :alpha:

, :digit:

etc.

Second, run the sign +

. By default, you should avoid this.

So your regex would be:

:0,$s/width="\d\+"//gc

      



And please read the help before posting to stackoverflow:

:h :s

      

You may also be interested in this help section:

:h magic 

      

+5


source


Do you want to:

:0,$s/ width="\d\+"//gc

      



\d

is not recognized within a character class (or rather, it is recognized as a letter d

), and +

without a backslash, it is not recognized as a vim

BRE metacharacter . You also probably want the space in front to width

be eliminated.

+1


source


It will only work with two digits wide, won't it?

0


source







All Articles