简体   繁体   English

Python-正则表达式查找字符串中第一个元音的位置

[英]Python - Regular Expression find position of first vowel in a string

How to use regular expression to find the position of first vowel in a string? 如何使用正则表达式查找字符串中第一个元音的位置?

eg string = 'this is the day!' 例如string ='今天是一天! 'i' is the first vowel and I want to have the position 2 (since i is the 3rd element in the string) “ i”是第一个元音,并且我想拥有位置2(因为i是字符串中的第三个元素)

What is I want to find the 2nd vowel, the 3rd, etc.? 我想找到第二个元音,第三个元音等等?

您不需要正则表达式,可以通过一个简单的列表理解来完成,位置为1

vowel_pos = [ i for i,v in enumerate(my_string) if v.lower() in ('a','e','i','o','u','y') ]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM