8 """ |
8 """ |
9 |
9 |
10 import json |
10 import json |
11 import sys |
11 import sys |
12 |
12 |
|
13 from PyQt6.QtCore import QRegularExpression |
|
14 |
13 |
15 |
14 def rxValidate(regexp, options): |
16 def rxValidate(regexp, options): |
15 """ |
17 """ |
16 Function to validate the given regular expression. |
18 Function to validate the given regular expression. |
17 |
19 |
18 @param regexp regular expression to validate (string) |
20 @param regexp regular expression to validate (string) |
19 @param options list of options (list of string) |
21 @param options list of options (list of string) |
20 @return tuple of flag indicating validity (boolean), error |
22 @return tuple of flag indicating validity (boolean), error |
21 string (string) and error offset (integer) |
23 string (string) and error offset (integer) |
22 """ |
24 """ |
23 try: |
25 rxOptions = QRegularExpression.PatternOption.NoPatternOption |
24 from PyQt6.QtCore import QRegularExpression |
26 if "CaseInsensitiveOption" in options: |
|
27 rxOptions |= QRegularExpression.PatternOption.CaseInsensitiveOption |
|
28 if "MultilineOption" in options: |
|
29 rxOptions |= QRegularExpression.PatternOption.MultilineOption |
|
30 if "DotMatchesEverythingOption" in options: |
|
31 rxOptions |= QRegularExpression.PatternOption.DotMatchesEverythingOption |
|
32 if "ExtendedPatternSyntaxOption" in options: |
|
33 rxOptions |= QRegularExpression.PatternOption.ExtendedPatternSyntaxOption |
|
34 if "InvertedGreedinessOption" in options: |
|
35 rxOptions |= QRegularExpression.PatternOption.InvertedGreedinessOption |
|
36 if "UseUnicodePropertiesOption" in options: |
|
37 rxOptions |= QRegularExpression.PatternOption.UseUnicodePropertiesOption |
|
38 if "DontCaptureOption" in options: |
|
39 rxOptions |= QRegularExpression.PatternOption.DontCaptureOption |
25 |
40 |
26 rxOptions = QRegularExpression.PatternOption.NoPatternOption |
41 error = "" |
27 if "CaseInsensitiveOption" in options: |
42 errorOffset = -1 |
28 rxOptions |= QRegularExpression.PatternOption.CaseInsensitiveOption |
43 re = QRegularExpression(regexp, rxOptions) |
29 if "MultilineOption" in options: |
44 valid = re.isValid() |
30 rxOptions |= QRegularExpression.PatternOption.MultilineOption |
45 if not valid: |
31 if "DotMatchesEverythingOption" in options: |
46 error = re.errorString() |
32 rxOptions |= QRegularExpression.PatternOption.DotMatchesEverythingOption |
47 errorOffset = re.patternErrorOffset() |
33 if "ExtendedPatternSyntaxOption" in options: |
|
34 rxOptions |= QRegularExpression.PatternOption.ExtendedPatternSyntaxOption |
|
35 if "InvertedGreedinessOption" in options: |
|
36 rxOptions |= QRegularExpression.PatternOption.InvertedGreedinessOption |
|
37 if "UseUnicodePropertiesOption" in options: |
|
38 rxOptions |= QRegularExpression.PatternOption.UseUnicodePropertiesOption |
|
39 if "DontCaptureOption" in options: |
|
40 rxOptions |= QRegularExpression.PatternOption.DontCaptureOption |
|
41 |
|
42 error = "" |
|
43 errorOffset = -1 |
|
44 re = QRegularExpression(regexp, rxOptions) |
|
45 valid = re.isValid() |
|
46 if not valid: |
|
47 error = re.errorString() |
|
48 errorOffset = re.patternErrorOffset() |
|
49 except ImportError: |
|
50 valid = False |
|
51 error = "ImportError" |
|
52 errorOffset = 0 |
|
53 |
48 |
54 return valid, error, errorOffset |
49 return valid, error, errorOffset |
55 |
50 |
56 |
51 |
57 def rxExecute(regexp, options, text, startpos): |
52 def rxExecute(regexp, options, text, startpos): |
68 (integer) for each entry |
63 (integer) for each entry |
69 """ |
64 """ |
70 valid, error, errorOffset = rxValidate(regexp, options) |
65 valid, error, errorOffset = rxValidate(regexp, options) |
71 if not valid: |
66 if not valid: |
72 return valid, error, errorOffset |
67 return valid, error, errorOffset |
73 |
|
74 from PyQt6.QtCore import QRegularExpression |
|
75 |
68 |
76 rxOptions = QRegularExpression.PatternOption.NoPatternOption |
69 rxOptions = QRegularExpression.PatternOption.NoPatternOption |
77 if "CaseInsensitiveOption" in options: |
70 if "CaseInsensitiveOption" in options: |
78 rxOptions |= QRegularExpression.PatternOption.CaseInsensitiveOption |
71 rxOptions |= QRegularExpression.PatternOption.CaseInsensitiveOption |
79 if "MultilineOption" in options: |
72 if "MultilineOption" in options: |