我有一个文件,其出现形式为_[number].htm,例如_43672151820.htm如何删除所有匹配模式的字符串?
_[number].htm
_43672151820.htm
pkwftd7m1#
替换子字符串
将此正则表达式与替换命令%s一起使用
%s
:%s/_\d\+\.htm//g
说明(来自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)
_ 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)
替换词
上面的正则表达式将匹配ab_123.htm中的123.htm。如果要匹配一个单词,请使用vim的 * 单词边界 * \<和\>:
ab_123.htm
123.htm
\<
\>
:%s/\<_\d\+\.htm\>//g
(see(第10页)
1条答案
按热度按时间pkwftd7m1#
替换子字符串
将此正则表达式与替换命令
%s
一起使用说明(来自regex101.com):
替换词
上面的正则表达式将匹配
ab_123.htm
中的123.htm
。如果要匹配一个单词,请使用vim的 * 单词边界 *\<
和\>
:(see(第10页)