def string_find_id(string, regex):
"""Find a marker's ID using a regular expression
returns the ID as int if found, otherwise returns None
Args:
-string, any string
-regex, the regex pattern to match."""
if not string and regex:
raise AttributeError("Missing name or regex attribute")
import re
index = re.search(regex, string)
if index:
found_id = index.group(1)
return int(found_id) if found_id else None
return None
评论列表
文章目录