我有一些大型 .txt 文件(有时超过 10K 行),其中包含 5 个字段,既有数字字段也有字母字段。我遇到的问题是第二和第三个字段是名字和姓氏,而其他字段都是数字。有没有办法让我只搜索名字和姓氏的列,并用空格替换任何数字或特殊字符?此外,是否可以使用“查找和替换”功能一次性列出我需要替换的所有字符,并将范围限制在 2 列?
以下是文件的示例;
200068897 LLC BLUES 25 6085264 20240209
201499188 LLC ACTION!! 6085269 20240209
201499188 LLC ACTION# 6085269 20240209
答案1
- Ctrl+H
- 找什么:
(?:^\d+\h+|\G(?!^))[a-z]*\K[^a-z](?=.*\h+\d+\h+\d+\h*$)
- 替换为:
#一个空格
- 取消勾选 相符
- 打钩 环绕
- 选择 正则表达式
- 取消勾选
. matches newline
- Replace all
解释:
(?: # non capture group
^ # beginning of line
\d+ # 1 or more digits
\h+ # 1 or more horizontal spaces
| # OR
\G # restart from last match position
(?!^) # not at the beginning of line
) # end group
[a-z]* # 0 or more letters
\K # forget all we have seen until this position
[^a-z] # a character that is not a letter
(?= # positive lookahead, make sure we have after:
.* # 0 or more any character
\h+ # 1 or more horizontal spaces
\d+ # 1 or more digits
\h+ # 1 or more horizontal spaces
\d+ # 1 or more digits
\h+ # 0 or more horizontal spaces
$ # end of line
) # end group
截图(之前):
截图(之后):