如何从 Python 中的输入文本中删除所有 re.findall 匹配项?
How to remove all re.findall matches from the inputed text, in Python?
我觉得应该是这样,但是不行
import re
RNA = input("")
regex = r"gu(?:\w{0,}?)ag"
introns = re.findall(regex, RNA)
exons = re.sub(introns, '', RNA)
print(exons)
但它应该删除 re.findall 找到的所有匹配项,或者将其替换为空的 space 或其他文本。
您不需要调用 re.findall()
,您可以使用正则表达式调用 re.sub
,所有匹配项都将被替换
import re
RNA = input("")
regex = r"gu(?:\w{0,}?)ag"
exons = re.sub(regex, '', RNA)
print(exons)
我觉得应该是这样,但是不行
import re
RNA = input("")
regex = r"gu(?:\w{0,}?)ag"
introns = re.findall(regex, RNA)
exons = re.sub(introns, '', RNA)
print(exons)
但它应该删除 re.findall 找到的所有匹配项,或者将其替换为空的 space 或其他文本。
您不需要调用 re.findall()
,您可以使用正则表达式调用 re.sub
,所有匹配项都将被替换
import re
RNA = input("")
regex = r"gu(?:\w{0,}?)ag"
exons = re.sub(regex, '', RNA)
print(exons)