所以问题很简单。经过几个小时的浏览有关正则表达式的线程,我仍然无法提出可以处理代码部分中所述的字符串的线程。
以下是我尝试过的一些正则表达式(为了阅读而不会转义反斜杠):
p2
这是我最接近的东西,除了:
0x7ffeec515a68
=COUNTIFS(A3:A20, ">5")
我期望的是
/\d+({.*?})(?:(|\d+|$|))/;
/\d+({.+})(?:(|\d+|$|))/;
/\d+({.*?})(?:(|\d+|\B|))/;
/\d+({.+})(?:(|\d+|\B|))/;
/\d+({.*?})(?:(|\d+|))/;
/\d+({.+})\d+/;
/\d+({.*?})\d+/;
我实际上得到的是:
/\d+({.*?})\d+|\d+({.*?})/
但完全匹配,我得到了:
QString haystack = "5:4{"type":"someType","data":{"subJson":123}}"\
"9406:22{"type":"SomeOtherType","data":{"subJson":648,"data":{"subSubJson":25}}}"\
"125:10{"last":79}"; // The quotes are obviously escaped but reading sake...
QRegularExpression re = QRegularExpression("\\d+({.*?})\\d+|\\d+({.*?})");
QRegularExpressionMatchIterator i = re.globalMatch(haystack);
QStringList matches;
while (i.hasNext()) {
QRegularExpressionMatch match = i.next();
QString result = match.captured(1); // Group match
matches << result;
}
qDebug() << matches;
答案 0 :(得分:1)
解决方案是:
/\d+({.*?})(?:\d+|$)/
首先检查带有'\ d +'的前置数字,然后对花括号之间的所有内容进行分组匹配而不用贪婪,因此匹配'({。*?})',最后将排除的分组匹配'?:'在一组数字'\ d +'或单词'$','(?:\ d + | $)'的末尾停止先前的组匹配