Skip to content

Commit

Permalink
Allow to detect matching group in finditer_with_separators().
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitri-Sintsov committed Nov 14, 2024
1 parent c88d0c5 commit af258ff
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion django_jinja_knockout/utils/regex.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# https://regexr.com
class MatchGroup(str):
pass


# regex can be without capturing group.
def finditer_with_separators(regex, s):
matches = []
Expand All @@ -6,7 +11,7 @@ def finditer_with_separators(regex, s):
match_start = match.start()
if (prev_end != 0 or match_start > 0) and match_start != prev_end:
matches.append(s[prev_end:match.start()])
matches.append(match.group())
matches.append(MatchGroup(match.group()))
prev_end = match.end()
if prev_end < len(s):
matches.append(s[prev_end:])
Expand Down

0 comments on commit af258ff

Please sign in to comment.