![如何使用正则表达式删除每一行最后一个单词的所有元音?](https://linux22.com/image/1650374/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E5%88%A0%E9%99%A4%E6%AF%8F%E4%B8%80%E8%A1%8C%E6%9C%80%E5%90%8E%E4%B8%80%E4%B8%AA%E5%8D%95%E8%AF%8D%E7%9A%84%E6%89%80%E6%9C%89%E5%85%83%E9%9F%B3%EF%BC%9F.png)
如何使用正则表达式删除每一行最后一个单词的所有元音?
例子:
Hello world!
The quick brown fox jumps over the lazy dog
结果:
Hello wrld!
The quick brown fox jumps over the lazy dg
答案1
- Ctrl+H
- 找什么:
[aeiou](?=[^aeiou]+$)
- 用。。。来代替:
LEAVE EMPTY
- 查看 环绕
- 查看 正则表达式
- Replace all
解释:
[aeiou] # a vowel
(?= # positive lookahead, make sure we have after:
[^aeiou]+ # 1 or more ay character that is not a vowel
$ # end of line
) # end lookahead
截图(之前):
截图(之后):
如果要在最后一个单词中删除超过 1 个元音,请使用:
- 找什么:
(?:\b|\G(?!^))[^aeiou ]*\K[aeiou]+(?=\S*$)
- 用。。。来代替:
LEAVE EMPTY
解释:
(?: # non capture group
\b # word boundary
| # OR
\G(?!^) # restart from last match posiiton, not at the beginning of line
) # end group
[^aeiou ]* # 0 or more any character not a vowel or space
\K # forget all we have seen until this position
[aeiou]+ # 1 or more vowel
(?= # positive lookahead, make sure we have, after:
\S* # 0 or more non space
$ # end of line
) # end lookahead