-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegexGobalMatchAndCombi.cpp
More file actions
113 lines (95 loc) · 3.68 KB
/
RegexGobalMatchAndCombi.cpp
File metadata and controls
113 lines (95 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "RegexGobalMatchAndCombi.h"
QString RegexGobalMatchAndCombi(QString text, QString findre, QString repre, int NO_start, int NO_Step, int ContinueTimes)
{
QString sourcetext = text;
QString rescript = findre;
QString incrstep = QString("%1").arg(ContinueTimes);
QRegularExpression::PatternOptions reflag = QRegularExpression::MultilineOption | QRegularExpression::ExtendedPatternSyntaxOption | QRegularExpression::CaseInsensitiveOption | QRegularExpression::DotMatchesEverythingOption | QRegularExpression::UseUnicodePropertiesOption;
QRegularExpression re(rescript, reflag);
auto MaIt = re.globalMatch(sourcetext);
QString replace_with_string = repre;
QString result_repladed_str;
int stepnum = NO_Step;
int startnum = NO_start - stepnum;
int nowstartnum = startnum;
int incrstepnum = incrstep.toInt();
if (incrstepnum <= 0)incrstepnum = 1;
while (MaIt.hasNext())
{
auto Ma = MaIt.next();
QString matotalstr = Ma.captured(0);
QString replace_with_string_cp = replace_with_string;
for (int gi = 0; gi <= Ma.lastCapturedIndex(); ++gi)
{
QString capstr = Ma.captured(gi);
capstr = capstr.replace(QRegularExpression("%(\\d)"), "%#*#\\1");
replace_with_string_cp=replace_with_string_cp.replace(QString("\\%1").arg(gi), capstr);
}
//
if (replace_with_string_cp.indexOf("%1") != -1)
replace_with_string_cp = replace_with_string_cp.arg(nowstartnum + stepnum);
incrstepnum--;
if (incrstepnum == 0)
{
nowstartnum += stepnum;
//
incrstepnum = incrstep.toInt();
}
//
result_repladed_str += replace_with_string_cp;
}
result_repladed_str = result_repladed_str.replace(QRegularExpression("%#[*]#(\\d)"), "%\\1");
return result_repladed_str;
}
QStringList RegexGobalMatchAndCombi_v_list(QString text, QString findre, QStringList reprelist, int NO_start, int NO_Step, int ContinueTimes)
{
QString sourcetext = text;
QString rescript = findre;
QString incrstep = QString("%1").arg(ContinueTimes);
QRegularExpression::PatternOptions reflag = QRegularExpression::MultilineOption | QRegularExpression::ExtendedPatternSyntaxOption | QRegularExpression::CaseInsensitiveOption | QRegularExpression::DotMatchesEverythingOption | QRegularExpression::UseUnicodePropertiesOption;
QStringList result_repladed_strls;
for (int i = 0; i < reprelist.size(); i++)
{
result_repladed_strls.push_back("");
}
int stepnum = NO_Step;
int startnum = NO_start - stepnum;
int nowstartnum = startnum;
int incrstepnum = incrstep.toInt();
if (incrstepnum <= 0)incrstepnum = 1;
QRegularExpression re(rescript, reflag);
auto MaIt = re.globalMatch(sourcetext);
while (MaIt.hasNext())
{
auto Ma = MaIt.next();
QString matotalstr = Ma.captured(0);
for (int i = 0; i < reprelist.size(); i++)
{
QString replace_with_string = reprelist[i];
QString replace_with_string_cp = replace_with_string;
for (int gi = 0; gi <= Ma.lastCapturedIndex(); ++gi)
{
QString capstr = Ma.captured(gi);
capstr = capstr.replace(QRegularExpression("%(\\d)"), "%#*#\\1");
replace_with_string_cp = replace_with_string_cp.replace(QString("\\%1").arg(gi), capstr);
}
//
if (replace_with_string_cp.indexOf("%1") != -1)
replace_with_string_cp = replace_with_string_cp.arg(nowstartnum + stepnum);
incrstepnum--;
if (incrstepnum == 0)
{
nowstartnum += stepnum;
//
incrstepnum = incrstep.toInt();
}
//
result_repladed_strls[i] += replace_with_string_cp;
}
}
for (int i = 0; i < reprelist.size(); i++)
{
result_repladed_strls[i] = result_repladed_strls[i].replace(QRegularExpression("%#[*]#(\\d)"), "%\\1");
}
return result_repladed_strls;
}