ich habe eine Datei, die ich in ein QByteArray einlese.
Das QBA wird in einen QString geschrieben, auf den eine RegExp angewendet wird.
Soweit ist das kein Problem. Allerdings wird nur für die ersten zwei Ergebnisse der RegExp ein Wert in "result" geschrieben. Die Anzahl der gefundenen matches ist aber richtig (6), auch die Länge der matches.
Code:
Code: Alles auswählen
QStringList progname::eval_RegExp(QRegExp rxIn, QByteArray rBArray) {
// evaluate a given ByteArray by RegExp rxIn
cout << "evaluating RegExp.." << endl;
int pos;
int cnt;
QString tmpString;
QString result;
QStringList resultList;
QString tmpst;
// initialize states..
tmpString = rBArray.data();
resultList.clear();
cnt = 0;
pos = 0;
result = "";
// search the given string by RegExg rxIn
while ((pos = rxIn.indexIn(tmpString, pos)) != -1) {
pos += rxIn.matchedLength();
cout << "pos: " << pos << ", len: " << rxIn.matchedLength() << ", cnt: " << cnt << endl;
result = rxIn.cap(cnt);
resultList.append(result);
cnt++;
cout << "RegExp Result: " << result.toStdString() << endl;
}
cout << "found: " << cnt << " matches"<< endl;
// cout << "size of resultList: " << resultList.size() << endl;
return resultList;
}
ausgewerteter QString:
### Ini-File Zuordnung
### name: zuordnung.txt
###
### "Code Definition"
###
AAEA----CA-AL---R---------HA-HUHc0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
AAEA----CA-AL--L----------HA-HUHc1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
AAEA----CA-AL--L----------HA-HUHc1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
AAEA----CA-AL---R---------HA-HUHc0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
AAEA----CA-AL----L--------HA-HUHc0010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
AAEA----CA-AL-----R-------HA-HUHc0001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Output:
pos: 224, len: 133, cnt: 0
RegExp Result: AAEA----CA-AL---R---------HA-HUHc0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
pos: 359, len: 133, cnt: 1
RegExp Result: AAEA----CA-AL--L----------HA-HUHc1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
pos: 494, len: 133, cnt: 2
RegExp Result:
pos: 629, len: 133, cnt: 3
RegExp Result:
pos: 764, len: 133, cnt: 4
RegExp Result:
pos: 899, len: 133, cnt: 5
RegExp Result:
found: 6 matches
angewandte RegExp:
QRegExp rxCode("([A-Z-]{32}[c]{1}[0-1]{100})");
Funktionsaufruf:
retval = eval_RegExp(rxCode, tByteArray);
Für Hilfe bin ich dankbar!
Gruß,
Torsten