이 페이지에서

QRegularExpressionMatchIterator Class

QRegularExpressionMatchIterator 클래스는 QRegularExpression 객체를 문자열에 대해 전역 일치 검색한 결과에 대한 이터레이터를 제공합니다. 더 보기...

헤더: #include <QRegularExpressionMatchIterator>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core

참고: 이 클래스의 모든 함수는 재진입 가능합니다.

공개 함수

QRegularExpressionMatchIterator()
QRegularExpressionMatchIterator(const QRegularExpressionMatchIterator &iterator)
(since 6.1) QRegularExpressionMatchIterator(QRegularExpressionMatchIterator &&iterator)
~QRegularExpressionMatchIterator()
bool hasNext() const
bool isValid() const
QRegularExpression::MatchOptions matchOptions() const
QRegularExpression::MatchType matchType() const
QRegularExpressionMatch next()
QRegularExpressionMatch peekNext() const
QRegularExpression regularExpression() const
void swap(QRegularExpressionMatchIterator &other)
QRegularExpressionMatchIterator &operator=(QRegularExpressionMatchIterator &&iterator)
QRegularExpressionMatchIterator &operator=(const QRegularExpressionMatchIterator &iterator)

상세 설명

QRegularExpressionMatchIterator 객체는 Java와 유사한 순방향 전용 이터레이터이며, QRegularExpression::globalMatch() 함수를 호출하여 얻을 수 있습니다. 새로운 QRegularExpressionMatchIterator는 첫 번째 결과 앞에 위치하게 됩니다. 그런 다음 hasNext() 함수를 호출하여 더 많은 결과가 있는지 확인할 수 있습니다. 결과가 더 있는 경우, next() 함수가 다음 결과를 반환하고 이터레이터를 다음 결과로 이동시킵니다.

각 결과는 해당 결과에 대한 모든 정보(캡처된 부분 문자열 포함)를 포함하는 ` QRegularExpressionMatch ` 객체입니다.

예를 들어:

// extracts the words
QRegularExpression re("(\\w+)");
QString subject("the quick fox");
QRegularExpressionMatchIterator i = re.globalMatch(subject);
while (i.hasNext()) {
    QRegularExpressionMatch match = i.next();
    // ...
}

또한, QRegularExpressionMatchIterator는 이터레이터를 진행시키지 않고 다음 결과를 가져올 수 있는 peekNext() 함수를 제공합니다.

Qt 6.0부터는 다음과 같이 범위 기반 for 루프에서 QRegularExpression::globalMatch 의 결과를 간단히 사용할 수도 있습니다:

// using a raw string literal, R"(raw_characters)", to be able to use "\w"
// without having to escape the backslash as "\\w"
QRegularExpression re(R"(\w+)");
QString subject("the quick fox");
for (const QRegularExpressionMatch &match : re.globalMatch(subject)) {
    // ...
}

regularExpression() 함수를 호출하여 대상 문자열과 일치된 QRegularExpression 객체를 가져올 수 있으며, matchType() 및 matchOptions()을 각각 호출하여 일치 유형과 일치 옵션을 확인할 수도 있습니다.

Qt 정규식 클래스에 대한 자세한 내용은 QRegularExpression 문서를 참조하십시오.

QRegularExpression 및 QRegularExpressionMatch도 참조하십시오 .

멤버 함수 문서

QRegularExpressionMatchIterator::QRegularExpressionMatchIterator()

유효한 빈 QRegularExpressionMatchIterator 객체를 생성합니다. 정규 표현식은 기본 생성된 것으로 설정되며, 일치 유형은 ` QRegularExpression::NoMatch `로, 일치 옵션은 ` QRegularExpression::NoMatchOption`로 설정됩니다.

생성된 객체에서 hasNext() 멤버 함수를 호출하면, 이터레이터가 유효한 일치 시퀀스를 순회하고 있지 않으므로 false가 반환됩니다.

QRegularExpressionMatchIterator::QRegularExpressionMatchIterator(const QRegularExpressionMatchIterator &iterator)

iterator 의 복사본으로 QRegularExpressionMatchIterator 객체를 생성합니다.

operator=()도 참조하십시오 .

[constexpr noexcept default, since 6.1] QRegularExpressionMatchIterator::QRegularExpressionMatchIterator(QRegularExpressionMatchIterator &&iterator)

iterator 에서 값을 이동하여 QRegularExpressionMatchIterator 객체를 생성합니다.

이동된 QRegularExpressionMatchIterator는 소멸되거나 할당될 수만 있다는 점에 유의하십시오. 소멸자나 할당 연산자 중 하나를 제외한 다른 함수를 호출할 경우 그 결과는 정의되지 않습니다.

이 함수는 Qt 6.1에서 도입되었습니다.

operator=()도 참조하십시오 .

[noexcept] QRegularExpressionMatchIterator::~QRegularExpressionMatchIterator()

QRegularExpressionMatchIterator 객체를 삭제합니다.

bool QRegularExpressionMatchIterator::hasNext() const

이터레이터 앞쪽에 일치 결과가 하나라도 있으면 ` true `를 반환하고, 그렇지 않으면 ` false`를 반환합니다.

next()도 참조하십시오 .

bool QRegularExpressionMatchIterator::isValid() const

이테레이터 객체가 유효한 QRegularExpression 객체에 대해 호출된 QRegularExpression::globalMatch() 함수의 결과로 얻어진 경우 true 을 반환하고, QRegularExpression 가 유효하지 않은 경우 false 을 반환합니다.

QRegularExpression::globalMatch() 및 QRegularExpression::isValid()도 참조하십시오 .

QRegularExpression::MatchOptions QRegularExpressionMatchIterator::matchOptions() const

이 QRegularExpressionMatchIterator 객체를 가져오는 데 사용된 매치 옵션, 즉 QRegularExpression::globalMatch()에 전달된 매치 옵션을 반환합니다.

QRegularExpression::globalMatch(), regularExpression(), matchType()도 참조하십시오 .

QRegularExpression::MatchType QRegularExpressionMatchIterator::matchType() const

이 QRegularExpressionMatchIterator 객체를 가져오는 데 사용된 매치 유형, 즉 QRegularExpression::globalMatch()에 전달된 매치 유형을 반환합니다.

QRegularExpression::globalMatch(), regularExpression() 및 matchOptions()도 참조하십시오 .

QRegularExpressionMatch QRegularExpressionMatchIterator::next()

다음 일치 결과를 반환하고 이터레이터를 한 칸씩 앞으로 이동시킵니다.

참고: 이터레이터가 결과 집합의 끝에 있을 때 이 함수를호출하면 정의되지 않은 결과가 발생합니다.

QRegularExpressionMatch QRegularExpressionMatchIterator::peekNext() const

이테레이터를 이동시키지 않고 다음 일치 결과를 반환합니다.

참고: 이터레이터가 결과 집합의 끝에 있을 때 이 함수를호출하면 정의되지 않은 결과가 발생합니다.

QRegularExpression QRegularExpressionMatchIterator::regularExpression() const

globalMatch() 함수가 이 객체를 반환한 QRegularExpression 객체를 반환합니다.

QRegularExpression::globalMatch(), matchType() 및 matchOptions()도 참조하십시오 .

[noexcept] void QRegularExpressionMatchIterator::swap(QRegularExpressionMatchIterator &other)

이 이터레이터를 other 와 서로 바꿉니다. 이 작업은 매우 빠르며 실패하는 일이 없습니다.

[noexcept] QRegularExpressionMatchIterator &QRegularExpressionMatchIterator::operator=(QRegularExpressionMatchIterator &&iterator)

iterator 를 이 객체로 이동 할당하고, 그 결과에 대한 참조를 반환합니다.

이동된 QRegularExpressionMatchIterator 는 소멸되거나 할당될 수만 있다는 점에 유의하십시오. 소멸자나 할당 연산자 중 하나를 제외한 다른 함수를 호출할 경우의 결과는 정의되지 않습니다.

QRegularExpressionMatchIterator &QRegularExpressionMatchIterator::operator=(const QRegularExpressionMatchIterator &iterator)

이 객체에 반복자 ` iterator `를 할당하고, 복사본에 대한 참조를 반환합니다.

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.