Nodepad++下正则表达式简单应用

正则表达式是一个文字处理的利器,曾经也专门学习过,不过到用的时候就不行了。 还是碰到问题边学习边总结吧。

需求

        rxjava2Version = '2.0.8'
        retrofit2Version = '2.2.0'
        rxlifecycle = '2.2.1'
        gsonVersion = '2.8.0'
        rxjava2adapter = '1.0.0'
        okhttp3interceptor = '3.10.0'
        autodispose = '1.4.0'

替换为:

"rxjava2Version" = "2.0.8"
"retrofit2Version" = "2.2.0"
"rxlifecycle" = "2.2.1"
"gsonVersion" = "2.8.0"
"rxjava2adapter" = "1.0.0"
"okhttp3interceptor" = "3.10.0"
"autodispose" = "1.4.0"

实现

1. 将每行开头添加 "

Ctrl +H      调出Notepad++ 替换窗口
查找目标:  ^\s+
替换为: "
选中匹配大小写
查找模式:正则表达式

Nodepad++下正则表达式简单应用_第1张图片
替换后效果

"rxjava2Version = '2.0.8'
"retrofit2Version = '2.2.0'
"rxlifecycle = '2.2.1'
"gsonVersion = '2.8.0'
"rxjava2adapter = '1.0.0'
"okhttp3interceptor = '3.10.0'
"autodispose = '1.4.0'

2. 将 = ’ 替换为 " = "

Nodepad++下正则表达式简单应用_第2张图片
替换后效果

"rxjava2Version" = "2.0.8'
"retrofit2Version" = "2.2.0'
"rxlifecycle" = "2.2.1'
"gsonVersion" = "2.8.0'
"rxjava2adapter" = "1.0.0'
"okhttp3interceptor" = "3.10.0'
"autodispose" = "1.4.0'

3.将行尾的’ 替换为"Nodepad++下正则表达式简单应用_第3张图片

替换后效果为:

"rxjava2Version" = "2.0.8"
"retrofit2Version" = "2.2.0"
"rxlifecycle" = "2.2.1"
"gsonVersion" = "2.8.0"
"rxjava2adapter" = "1.0.0"
"okhttp3interceptor" = "3.10.0"
"autodispose" = "1.4.0"

参考内容: https://blog.csdn.net/weixin_34032792/article/details/91911426

你可能感兴趣的:(开发小技巧,正则表达式,notepad++)