开发者

String Matching with regular expressions

开发者 https://www.devze.com 2023-01-27 22:35 出处:网络
I am trying to write a regular expression in Python which takes a string and check开发者_如何学运维s if:

I am trying to write a regular expression in Python which takes a string and check开发者_如何学运维s if:

  1. The last character is a vowel.
  2. The last 2 characters are not the same.

This is what I came up with:

[aeiou]$

Can anybody help me with point number 2: last 2 characters are not the same. For example, expresso is valid and expressoo is not valid.


It might be easier to do this without a regular expression.

e.g if s[-2]!=s[-1] and s[-1] in 'aeiou'


(?i)([aeiouy])(?!\1)[aeiouy]$

EDIT:

This is also appealing for not having a repeat:

(?i)(?=[aeiouy]{2}$)(.)(?!\1).


Best I can do:

r"\w*(?:[^a\W]a|[^e\W]e|[^i\W]i|[^u\W]u|[^o\W]o)\b"
0

精彩评论

暂无评论...
验证码 换一张
取 消