Python正则表达式:';exceptions.Indexer错误:字符串索引超出范围';
我使用一个简单的正则表达式替换格式为'id=“111111”的字符串实例。这些字符串是作为使用scrapy生成的网页响应的一部分派生的,并使用另一个正则表达式进行过滤,以仅提供所需的输出。我正在以以下方式使用re.sub:Python正则表达式:';exceptions.Indexer错误:字符串索引超出范围';,python,regex,scrapy,Python,Regex,Scrapy,我使用一个简单的正则表达式替换格式为'id=“111111”的字符串实例。这些字符串是作为使用scrapy生成的网页响应的一部分派生的,并使用另一个正则表达式进行过滤,以仅提供所需的输出。我正在以以下方式使用re.sub: match3 = re.sub("/id="[0-9]+"/", ' ', match3) 但是,这会引发以下错误: exceptions.IndexError: string index out of range 谁能给我解释一下这里的问题是什么 谢谢 python中的
match3 = re.sub("/id="[0-9]+"/", ' ', match3)
但是,这会引发以下错误:
exceptions.IndexError: string index out of range
谁能给我解释一下这里的问题是什么
谢谢
“[0-9…
match3 = re.sub( 'id="\d+"', ' ', match3 ) # using a different enclosure
或
match3 = re.sub( "id=\"[0-9]+\"", ' ', match3 ) # escaping the "