简体   繁体   中英

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!' 'i' is the first vowel and I want to have the position 2 (since i is the 3rd element in the string)

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') ]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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