0

I've a file with occurence in the form _[number].htm, for example _43672151820.htm

How I can remove all occurrences of strings with a matching pattern?

user2314737
  • 27,088
  • 20
  • 102
  • 114
Giuseppe
  • 2,093
  • 1
  • 21
  • 26

1 Answers1

2

Substitute substring

Use this regular expression with the substitution command %s

:%s/_\d\+\.htm//g

Explanation (from regex101.com):

_ matches the character _ with index 9510 (5F16 or 1378) literally (case sensitive)
\d matches a digit (equivalent to [0-9])
\+ matches the character + with index 4310 (2B16 or 538) literally (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
htm matches the characters htm literally (case sensitive)
Global pattern flags 
g modifier: global. All matches (don't return after first match)

Substitute word

The above regular expression will match for instance 123.htm in ab_123.htm. If you want to match a word use vim's word boundaries\< and \>:

:%s/\<_\d\+\.htm\>//g

(see In Vim, how do you search for a word boundary character, like the \b in regexp?)

user2314737
  • 27,088
  • 20
  • 102
  • 114