正则表达式显示句子的首字母,用星号或点替换剩余的字母

Joe*_*Joe 5 powershell notepad++ regex batch

我试图找到一个正则表达式来替换这种格式的文本

balle spaziali
bambole e botte
calda emozione
fuori di testa
giovani diavoli
ragazze vincenti
ore contate
Run Code Online (Sandbox Code Playgroud)

通过这种方式

b.... s.......
b...... e b.....
c.... e......
f.... d. t....
g...... d......
r...... v.......
o.. c......
Run Code Online (Sandbox Code Playgroud)

你有想法吗?

我使用 notepad++ 作为文本编辑器,我不知道我是否需要批处理或 powershell 脚本。
谢谢你的任何建议

Tot*_*oto 12

  • Ctrl+H
  • 找什么: (?<![^a-z])(?<!^)[a-z]
  • 用。。。来代替: .
  • 取消选中 匹配案例
  • 检查 环绕
  • 检查 正则表达式
  • Replace all

解释:

(?<![^a-z])     # negative lookbehind, make sure we haven't a non-letter before
(?<!^)          # negative lookbehind, make sure we aren't at the beginning of line
[a-z]           # a letter
Run Code Online (Sandbox Code Playgroud)

截图(之前):

在此处输入图片说明

截图(后):

在此处输入图片说明


dbe*_*ham 5

您只需要一个正则表达式来标识要转换的字符。这很简单,以下任一方法都可以:\B\S, 或\B\w

现在您需要一个工具将所有匹配的字符转换为 .

我不使用记事本++,所以我不能说你会怎么做。但这很简单,使用我的JREPL.BAT正则表达式查找/替换命令行实用程序。

假设您要转换为文件“file.txt”:

jrepl "\B\S" "." /f file.txt /o -
Run Code Online (Sandbox Code Playgroud)

或者

jrepl "\B\w" "." /f file.txt /o -
Run Code Online (Sandbox Code Playgroud)

如果将命令放在批处理脚本中,则需要使用,call jrepl因为 JREPL 本身就是批处理脚本。如果没有 CALL,您将不会返回到您的脚本。

您还可以转换管道文本。这是一个简单的例子:

C:\test>echo hello world|jrepl "\B\S" "."
h.... w....
Run Code Online (Sandbox Code Playgroud)

  • 奇怪的是,在 Notepad++ (7.6.4) 中,这只替换每隔一个字母。很可能是因为它在每次替换后重新应用正则表达式。 (2认同)