2024-09-26 22:49:54 发布
网友
只想找到第一次出现的“com”或“org”。 我试过:
comIndex = domain.index(r '(?: com|org)')
但它不起作用。有人能纠正我吗?你知道吗
import re comIndex = -1 m = re.search(r'(?:com|org)', domain) if m: comIndex = m.start() print comIndex
我认为你不能像这样使用正则表达式。Python中的Regex不是内置特性,您需要import the ^{} module才能使用其中的方法。你知道吗
import re ... comMatch = re.search('com|org', domain) if comMatch: comIndex = comMatch.start()
怎么样
re.search('(com)|(org)',domain).span()[0]
我认为你不能像这样使用正则表达式。Python中的Regex不是内置特性,您需要import the ^{} module 才能使用其中的方法。你知道吗
怎么样
相关问题 更多 >
编程相关推荐