String Matching with regular expressions
I am trying to write a regular expression in Python which takes a string and check开发者_如何学运维s if:
- The last character is a vowel.
- 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"
精彩评论