import re
entity_startindex = [i.start() for i in re.finditer(temp_label[0], sentecen)]
其中temp_label[0]是子字符串,sentecen是待查找的字符串,如果多次出现都会查找到首位置的index下标
本文介绍如何使用Python的正则表达式模块re来查找一个字符串中所有子字符串的位置,通过finditer方法获取匹配对象,进而得到每个匹配的起始索引。
import re
entity_startindex = [i.start() for i in re.finditer(temp_label[0], sentecen)]
其中temp_label[0]是子字符串,sentecen是待查找的字符串,如果多次出现都会查找到首位置的index下标

被折叠的 条评论
为什么被折叠?