I can find previous match with this, but what I can't do, is to capture the length of the matched string:
int pos = 0;
if((pos = text.lastIndexOf(QRegularExpression(pattern), cursorPosition - 1)) != -1))
cout << "Match at position: " << pos << endl;
I can capture the length of the match with QRegularExpressionMatch
, but I could not find any flag/option in the QRegularExpression
nor QRegularExpressionMatch
classes that would change the direction of the search. (I don't mean to reverse the pattern, but finding the first match before a certain position in a string.)
Example (I want to find not-even-regex "hello"
):
hello world hello
^
start (somewhere in the middle)
And this should be the matched section:
hello world hello
^ ^
start end
Thank you in advance.