我有一个一行中的单词列表,用逗号和引号分隔,如下所示:
“单词 1”,“单词 2”,“单词 3”...
我想知道我是否可以删除长度超过 9 个字符的单词。我该怎么做?如果需要,我可以使用 Notepad++。
答案1
您可以使用 Powershell 来执行此操作:
文件测试.txt:
"xxxxxx7","xxxxxxx8","xxxxxxxx9","xxxxxxxx10","xxxxxxxxx11"
电源外壳:
get-content test.txt | foreach-Object {
$_.Split(',')
} | % {if($_.length -lt 12) {$_}} | & {$ofs=',';"$input"} | out-file test2.txt
测试2.txt:
"xxxxxx7","xxxxxxx8","xxxxxxxx9"
-lt 12 表示低于 12(9 个字符 + 2 个引号 = 11)
答案2
- Ctrl+H
- 找什么:
"[^"]{10,}",?
- 用。。。来代替:
LEAVE EMPTY
- 检查环绕
- 检查正则表达式
- Replace all
解释:
" # a double quote
[^"]{10,} # 10 or more non quote character
" # a double quote
,? # an optional comma
输入示例:
"word","wordword","wordwordword","word"
输出:
"word","wordword","word"