我想删除用户名中其他字符前后包含少于 3 个字母的所有行,但我不需要对密码进行任何更改,这就是为什么我在“:”之前说
完整示例文件包含:
@user1example:keepline6
~!@#$%^&*(1)_+:deleteline1
..........:deleteline2
[45364\H]..;".:deleteline3
t!esting.1:keepline9
...+++#$29:deleteline4
5666D6666X67:deleteline32
namestart:keepline0
..............:deleteline8
____________:deleteline7
~!@#$%^&*()+=_-[]{}\/';.<>,:deleteline11
1start$go2deep_:keepline20
#(gold2bestar):keepline15
%%....^\/~`"':deleteline50
...e...y%%..~@:deleteline14
A``!!!!236g...:deleteline17
username9example1:5password0example1
554425$%^921:deleteline18
+++++++++++++++++:deleteline74
use123:keepline100
.....E_______:deleteline43
!!!!!!!!!!!P:deleteline47
Dy!!..,,(_)*&:deleteline49
&####...$,,,,,FW:deleteline66
4644848We:deleteline84
Zx5654644889:deleteline96
21Gt:deleteline89
@dF.:deleteline67
[email protected]:password12
¥5G5Y.....:deleteline94
[email protected]:password1
需要结果:
@user1example:keepline6
t!esting.1:keepline9
namestart:keepline0
1start$go2deep_:keepline20
#(gold2bestar):keepline15
username9example1:5password0example1
use123:keepline100
[email protected]:password12
[email protected]:password1
答案1
- Ctrl+H
- 找什么:
^(?:[^a-z]*[a-z]){0,2}[^a-z:]*:.*\R|^[^:]{0,2}:.*\R|^[^:]*:.{0,2}\R
- 用。。。来代替:
EMPTY
- Replace all
解释:
^ : begining of line
(?: : start non capture group
[^a-z]* : 0 or more any character that is not a letter
[a-z] : a letter
){0,2} : group is repêated up to 2 times
[^a-z:]* : 0 or more character that is not letter or :
: : literally :
.* : 0 or more any character
\R : any kind of line break
| : OR
^ : begining of line
[^:]{0,2} : 0 up to 2 character that is not :
: : literally :
.* : 0 or more any character
\R : any kind of line break
| : OR
^ : begining of line
[^:]* : 0 or more character that is not :
: : literally :
.{0,2} : up to 2 any character
\R : any kind of line break
- 请勿检查
. matches newline
给定示例的结果:
@user1example:keepline6
t!esting.1:keepline9
namestart:keepline0
1start$go2deep_:keepline20
#(gold2bestar):keepline15
username9example1:5password0example1
use123:keepline100
[email protected]:password12
[email protected]:password1