📜  Python – 在元音上分割字符串

📅  最后修改于: 2022-05-13 01:55:32.076000             🧑  作者: Mango

Python – 在元音上分割字符串

给定一个字符串,对元音执行拆分。

方法:使用 regex() + split()

在此,我们使用正则表达式 split(),它接受多个字符来执行拆分,传递元音列表,对字符串执行拆分操作。

Python3
# Python3 code to demonstrate working of
# Split String on vowels
# Using split() + regex
import re
 
# initializing strings
test_str = 'GFGaBste4oCS'
 
# printing original string
print("The original string is : " + str(test_str))
 
# splitting on vowels
# constructing vowels list
# and separating using | operator
res = re.split('a|e|i|o|u', test_str)
 
# printing result
print("The splitted string : " + str(res))


输出
The original string is : GFGaBste4oCS
The splitted string : ['GFG', 'Bst', '4', 'CS']