本文整理汇总了Python中match.Match.join_matches方法的典型用法代码示例。如果您正苦于以下问题:Python Match.join_matches方法的具体用法?Python Match.join_matches怎么用?Python Match.join_matches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类match.Match
的用法示例。
在下文中一共展示了Match.join_matches方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: match_zero_or_more
# 需要导入模块: from match import Match [as 别名]
# 或者: from match.Match import join_matches [as 别名]
def match_zero_or_more(self, text, index=0):
"""
Accumulates zero or more matches into a single Match object.
This will always return a Match, (0 or 1) = true
"""
accumulated_match = Match(index, '')
while True:
start_index = index + len(accumulated_match.text)
match = self.match_all_sub_queries(text, start_index)
if match and match.index == start_index:
accumulated_match = Match.join_matches([accumulated_match, match])
else: break
return accumulated_match
示例2: match_all_sub_queries
# 需要导入模块: from match import Match [as 别名]
# 或者: from match.Match import join_matches [as 别名]
def match_all_sub_queries(self, text, index=0):
"""
Recursively matches all subqueries in this Query.
This function searches left to right for matches to subqueries.
For each subquery, if a match is found, then:
if it is adjacent to the last match or it is the first match
for this query, we add it to the matches array
otherwise, we empty the matches array and start searching from
the first subquery again
If at any point no match for a subquery is found, we return None
Once we have found matches for all subqueries, we join all matches
into a single Match object, which is then returned.
"""
while index < len(text):
matches = []
for i, query in enumerate(self.queries):
match = None
if type(query) is str:
found_index = text.find(query, index)
match = Match(found_index, query)
else:
match = query.match(text, index)
if match is None or match.index == -1: return None
if matches == [] or index == match.index:
index = match.index + len(match.text)
matches.append(match)
elif index != 0 and index != match.index:
curr_match = Match.join_matches(matches)
if len(curr_match.text) == 0:
index += 1
break
else:
return None
else:
return Match.join_matches(matches)
return None