import re
list=["22.11","23","66.7f","123abcde","Case44","Happy","78","66.7","yes123","Book111"]
def removeInt(list):
for str in list:
if re.match("\d+",str):
result=re.search("\d+",str)
print("Original sentence:", str)
print("Found integer",result.group(0),"at the beginning of the string, starting index",result.start(),"and ending index at index",result.end(),".The rest of the string is:"**???????????**)
removeInt(list)
大家好,我目前正在做一个python正则表达式练习,以上是我目前的代码。 在输出的末尾,如果我想在从字符串中删除整数后显示字符串的其余部分。 我可以使用什么功能
以下是一个输出示例:
Original sentence: “90years”
Found integer 90 at the beginning of this string, starting at index _ ending at index _. The rest of the string is: years.
我想您可以使用.find()字符串方法
find()方法的语法为:
其中:
您可能会发现使用组捕获数字及其前后的字符串部分更容易。注意:我假设您不想在第一组之后匹配其他数字:
输出:
相关问题 更多 >
编程相关推荐