当前位置:网站首页>正则表达式保留【匹配范围内的内容】,然后替换【匹配范围之外的内容】
正则表达式保留【匹配范围内的内容】,然后替换【匹配范围之外的内容】
2022-07-15 17:01:00 【Old_Driver_Lee】
一、替换匹配范围之外的内容,要求如下:
如题,当前有格式为:
规则40:****
规则41:****
规则42:****
...
规则50:****
规则51:****
...
需要删除后面4个星号,替换为:(要求:删除星号以后,数字序号不能变)
规则40:
规则41:
规则42:
...
规则50:
规则51:
...
二、正则表达式为:
%s/规则\([4-9][0-9]\):\*\*\*\*/规则\1:/gc
三、释义
命令框架:
%s/AAA/BBB/gc 该命令为全局匹配AAA,并替换为BBB,
参数gc表示:每次用户输入Y确认替换,输入N不替换,具体含义不再赘述
命令释义:
[4-9][0-9] 为匹配2个字符,第一个字符范围为4-9,第二个字符范围为0-9
\([4-9][0-9]\) 符号\(\)括起来的部分表示一个整体表达式,后面的\1就表示该表达式原封不动放在这
备注:
\(\)括起来的部分按顺序表达式1 表达式2 表达式3递增,此命令只有一个表达式,\1
如:
\(aa\)\(bb\)\(cc\)
其中:
aa为表达式1,使用\1进行调用
bb为表达式2,使用\2进行调用
cc为表达式3,使用\3进行调用
\1 表示上述\(\)括起来的表达式
四、核心内容:表达式符号
此次删除/替换动作,主要用到了正则表达式中的“表达式”选项,
用 \(\) 括起来的表达式,使用\1\2\3\...依次递增表示。
\1 表示第1个表达式
\2 表示第2个表达式
\3 表示第3个表达式
...
边栏推荐
- 8. MySQL -- trigger
- Redis introduction and installation
- linq 实现查询字符串拼接 : And 和 OR 两种方式
- [problems of dft/fft - solutions to fence effect]
- (戴尔灵越7572)笔记本外扩显示器以后,笔记本没有声音了的解决办法
- 2021年全国职业院校技能大赛(中职组)网络安全竞赛试题(9)思路
- A rate distortion optimization of h264 encoder (1)
- “智慧工厂”上线,破局传统工厂数字化转型
- Array and string assignment problem (not initialized when defining)
- C语言:使用宏重定义printf,打印【debug调试信息】
猜你喜欢

How to quickly learn SQL for beginners

PD QC decoy power application IC "liderui ldr6328s" is widely used in all sizes of household appliances

基于TaskScheduler和CronTask实现动态增删启停定时任务功能

compileflow 淘宝工作流引擎

非对称加密RSA与对称加密AES项目应用

初学者怎么快速学会SQL

8. MySQL -- 触发器

Chapter 7 preprocessing of C language

Debug system

flowable 自定义属性实现和属性获取小记
随机推荐
Business development stagnates, decision-making is not supported by information, and data analysis is the solution
Live broadcast artifact Lavalier wireless microphone-ldr6028 power charging OTG scheme
flowable 自定义属性实现和属性获取小记
Ffmpeg sample analysis: muting c
The characteristics and underlying principles of synchronized, as well as the state and expansion and upgrading process of locks
9. MySQL -- JDBC入门
[interview must brush 101] hash
Getting started with OpenCV ----- vs how to install opencv Library
TP5的一些查询
Wm8960 sound card related problems
在数组中指定位置插入任意一个元素及删除数组中值为x的元素
Switching with file system in OTA upgrade
Gridsearchcv reported an error: valueerror: input contains Nan, infinity or a value too large for dtype ('float64 ')
8. MySQL -- 触发器
vim中如何贪婪匹配
Linked list implementation of C language stack
7. MySQL -- 基础语法(三) DCL
自增(自减)运算符的运算优先级
Markdown learning notes Chapter 2 basic grammar (displayed under the markdown editor)
Ldr9201 audio digital decoding DAC plus ldr6023c digital plus PD fast charging scheme