regex scanner groups findall tuple bug fixed

This commit is contained in:
sohyeonhwang 2019-12-12 07:47:07 -06:00
parent 097c60a7bc
commit 950ed8fde9
2 changed files with 13 additions and 2 deletions

View File

@ -320,7 +320,8 @@ class Test_Regex(unittest.TestCase):
# sample inputs for checking the outcomes of good inputs / test_basic_regex
self.good_inputs_list = [
"-RP '\\b\\d{3}\\b' -RPl threedigits",
"-RP 'TestCase' -RP 'page' -RPl testcases -RPl page_word",
#"-RP 'TestCase' -RP 'page' -RPl testcases -RPl page_word",
"-RP '(\\b[a-zA-Z]{3}\\b)' -RPl 3LETTERS -RP '(\\b(1[\d+])|(2[\d+])\\b)' -RPl NUMBERS",
"-CP 'Chevalier' -CPl chev_com -RP 'welcome to Wikipedia' -RPl wiki_welcome -CP 'Warning' -CPl warning",
"-CP 'WP:EVADE' -CPl wp_evade"
]

12
wikiq
View File

@ -189,7 +189,17 @@ class RegexPair(object):
#given that there are matches to be made
if self.pattern.search(content) is not None:
m = self.pattern.findall(content)
temp_dict[self.label] = ', '.join(m)
m_fixed = []
for match in m:
if type(match) is tuple:
matchies = set()
for sub_m in match:
matchies.add(sub_m)
m_fixed += matchies
else:
m_fixed.append(match)
temp_dict[self.label] = ', '.join(m_fixed)
else:
temp_dict[self.label] = None