From kwrite-devel Mon Dec 19 21:07:35 2011 From: Dominik Haumann Date: Mon, 19 Dec 2011 21:07:35 +0000 To: kwrite-devel Subject: Re: KTextEditor::SearchInterface Message-Id: <201112192207.36176.dhdev () gmx ! de> X-MARC-Message: https://marc.info/?l=kwrite-devel&m=132432900701979 Hi, the documentation [1] of searchText() says: When searching for regular expressions, the first element holds the range of the full match, the subsequent elements hold the ranges of the capturing parentheses. In other words, it always only searches for the first match. The return value is a QVector, because it may contain capturing sequences. [1] http://api.kde.org/4.x-api/kdelibs-apidocs/interfaces/ktexteditor/html/classKTextEditor_1_1SearchInterface.html You simply need to add a while-loop. For instance, I do it like this in part/plugins/hlselection/hlselectionplugin.cpp: KTextEditor::SearchInterface* siface = qobject_cast(m_view->document()); if (!siface) { return; } KTextEditor::Cursor start(0, 0); KTextEditor::Range searchRange; QVector matches; do { searchRange.setRange(start, m_view->document()->documentEnd()); matches = siface->searchText(searchRange, m_currentText, KTextEditor::Search::WholeWords); if (matches.first().isValid()) { // I got a valid match. Do something with it. //matches.first() .... // ...or simply add the match to a list: myMatches.append(matches.first()); // now adapt the start of the search range and continue start = matches.first().end(); } } while (matches.first().isValid()); This really should work for you. Dominik _______________________________________________ KWrite-Devel mailing list KWrite-Devel@kde.org https://mail.kde.org/mailman/listinfo/kwrite-devel