如何使用正则表达式删除每一行最后一个单词的所有元音?

如何使用正则表达式删除每一行最后一个单词的所有元音?

如何使用正则表达式删除每一行最后一个单词的所有元音?

例子:

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

相关内容