且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检查字符串是否有4个连续的字符后没有元音

更新时间:2023-11-26 10:32:40

edit:您可以为此使用以下正则表达式:

Based on your latest edit: You can use following regex for this:

^(?!.*?[^aeiou]{5})(?!.*?[aeiou]{3})[a-z]*$



在线演示: http://regex101.com/r/vM0aN9



分拆:

Online Demo: http://regex101.com/r/vM0aN9

Breaking it down:


  • [^ aeiou] = >匹配任何东西,除了元音之外

  • (?!*。[^ aeiou] {5}) =>没有5个连续辅音的情况

  • (?!。*?[aeiou] {3}) =>没有连续3个元音的情况

  • [az] * =>确保输入中只有字母

  • [^aeiou] => Match anything but vowels
  • (?!.*?[^aeiou]{5}) => Negative lookahead to make sure there is no case of 5 consecutive consonants
  • (?!.*?[aeiou]{3}) => To make sure there is no case of 3 consecutive vowels
  • [a-z]* => To make sure there are only letters in the input