Use stdlib re for dialogue matching
This commit is contained in:
@@ -24,30 +24,19 @@ import re
|
||||
|
||||
import pytest
|
||||
|
||||
from PyQt5.QtCore import QRegularExpression
|
||||
|
||||
from novelwriter import CONFIG
|
||||
from novelwriter.constants import nwUnicode
|
||||
from novelwriter.text.patterns import REGEX_PATTERNS
|
||||
|
||||
|
||||
def allMatches(regEx: QRegularExpression, text: str) -> list[list[str]]:
|
||||
def allMatches(regEx: re.Pattern, text: str) -> list[list[str]]:
|
||||
"""Get all matches for a regex."""
|
||||
result = []
|
||||
if isinstance(regEx, QRegularExpression):
|
||||
itt = regEx.globalMatch(text, 0)
|
||||
while itt.hasNext():
|
||||
match = itt.next()
|
||||
result.append([
|
||||
(match.captured(n), match.capturedStart(n), match.capturedEnd(n))
|
||||
for n in range(match.lastCapturedIndex() + 1)
|
||||
])
|
||||
else:
|
||||
for match in re.finditer(regEx, text):
|
||||
result.append([
|
||||
(match.group(n), match.start(n), match.end(n))
|
||||
for n in range((match.lastindex or -1) + 1)
|
||||
])
|
||||
for match in re.finditer(regEx, text):
|
||||
result.append([
|
||||
(match.group(n), match.start(n), match.end(n))
|
||||
for n in range((match.lastindex or 0) + 1)
|
||||
])
|
||||
return result
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user