Skip to content

Commit 632c245

Browse files
committed
Simplify regex pattern in get_leaders
1 parent f27a5a9 commit 632c245

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

backend/apps/owasp/models/common.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from __future__ import annotations
44

5-
import itertools
65
import logging
76
import re
87
from urllib.parse import urlparse
@@ -198,17 +197,23 @@ def get_leaders(self):
198197

199198
leaders = []
200199
for line in content.split("\n"):
201-
leaders.extend(
202-
[
203-
name
204-
for name in itertools.chain(
205-
*re.findall(
206-
r"[-*]\s*\[\s*([^(]+?)\s*(?:\([^)]*\))?\]|\*\s*([\w\s]+)", line.strip()
207-
)
208-
)
209-
if name.strip()
210-
]
200+
stripped_line = line.strip()
201+
names = []
202+
203+
bracketed_pattern = (
204+
r"[-*]\s{0,3}\[\s{0,3}([^\]\(]{1,200})"
205+
r"(?:\s{0,3}\([^)]{0,100}\))?\s{0,3}\]"
211206
)
207+
names.extend(re.findall(bracketed_pattern, stripped_line))
208+
names.extend(re.findall(r"\*\s{0,3}([\w\s]{1,200})", stripped_line))
209+
210+
cleaned_names = []
211+
for raw_name in names:
212+
if raw_name.strip():
213+
cleaned = re.sub(r"\s{0,3}\([^)]{0,100}\)\s{0,3}$", "", raw_name).strip()
214+
cleaned_names.append(cleaned)
215+
216+
leaders.extend(cleaned_names)
212217

213218
return leaders
214219

0 commit comments

Comments
 (0)