QRegularExpressionMatch Class
QRegularExpressionMatch 클래스는 QRegularExpression 을 문자열과 일치시킨 결과를 제공합니다. 더 보기...
Header: | #include <QRegularExpressionMatch> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
- 상속된 멤버를 포함한 모든 멤버 목록
- QRegularExpressionMatch는 암시적으로 공유되는 클래스 및 문자열 데이터용 클래스의 일부입니다.
참고: 이 클래스의 모든 함수는 재진입됩니다.
공용 함수
QRegularExpressionMatch() | |
QRegularExpressionMatch(const QRegularExpressionMatch &match) | |
(since 6.1) | QRegularExpressionMatch(QRegularExpressionMatch &&match) |
~QRegularExpressionMatch() | |
QString | captured(QAnyStringView name) const |
QString | captured(int nth = 0) const |
qsizetype | capturedEnd(QAnyStringView name) const |
qsizetype | capturedEnd(int nth = 0) const |
qsizetype | capturedLength(QAnyStringView name) const |
qsizetype | capturedLength(int nth = 0) const |
qsizetype | capturedStart(QAnyStringView name) const |
qsizetype | capturedStart(int nth = 0) const |
QStringList | capturedTexts() const |
QStringView | capturedView(QAnyStringView name) const |
QStringView | capturedView(int nth = 0) const |
(since 6.3) bool | hasCaptured(QAnyStringView name) const |
(since 6.3) bool | hasCaptured(int nth) const |
bool | hasMatch() const |
bool | hasPartialMatch() const |
bool | isValid() const |
int | lastCapturedIndex() const |
QRegularExpression::MatchOptions | matchOptions() const |
QRegularExpression::MatchType | matchType() const |
QRegularExpression | regularExpression() const |
void | swap(QRegularExpressionMatch &other) |
QRegularExpressionMatch & | operator=(QRegularExpressionMatch &&match) |
QRegularExpressionMatch & | operator=(const QRegularExpressionMatch &match) |
관련 비회원
QDebug | operator<<(QDebug debug, const QRegularExpressionMatch &match) |
상세 설명
QRegularExpressionMatch 객체는 QRegularExpression::match() 함수를 호출하거나 QRegularExpressionMatchIterator 에서 전역 일치의 단일 결과로 얻을 수 있습니다.
일치 시도의 성공 또는 실패는 hasMatch() 함수를 호출하여 검사할 수 있습니다. QRegularExpressionMatch는 hasPartialMatch() 함수를 통해 부분 일치 성공도 보고합니다.
또한 QRegularExpressionMatch는 패턴 문자열에서 캡처 그룹에 의해 캡처된 하위 문자열을 반환합니다. 인덱스가 0인 암시적 캡처 그룹은 전체 일치 결과를 캡처합니다. captured () 함수는 캡처 그룹의 인덱스 또는 이름에 따라 캡처된 각 하위 문자열을 반환합니다:
QRegularExpression re("(\\d\\d) (?<name>\\w+)"); QRegularExpressionMatch match = re.match("23 Jordan"); if (match.hasMatch()) { QString number = match.captured(1); // first == "23" QString name = match.captured("name"); // name == "Jordan" }
캡처된 각 하위 문자열에 대해 각각 capturedStart() 및 capturedEnd() 함수를 호출하여 제목 문자열의 시작 및 끝 오프셋을 쿼리할 수 있습니다. 캡처된 각 하위 문자열의 길이는 capturedLength() 함수를 사용하여 확인할 수 있습니다.
편의 함수 capturedTexts()는 캡처 그룹에 의해 캡처된 순서대로 캡처된 모든 하위 문자열(전체 패턴과 일치하는 하위 문자열 포함)을 한 번에 반환합니다(즉, captured(i) == capturedTexts().at(i)
).
regularExpression() 함수를 호출하여 주제 문자열이 일치된 QRegularExpression 객체를 검색할 수 있으며, matchType() 및 matchOptions()를 각각 호출하여 일치 유형 및 일치 옵션도 사용할 수 있습니다.
Qt 정규 표현식 클래스에 대한 자세한 내용은 QRegularExpression 문서를 참조하십시오.
QRegularExpression 를참조하세요 .
멤버 함수 문서
QRegularExpressionMatch::QRegularExpressionMatch()
유효한 비어 있는 QRegularExpressionMatch 객체를 생성합니다. 정규식은 기본적으로 구성된 정규식으로 설정되며, 일치 유형은 QRegularExpression::NoMatch 으로, 일치 옵션은 QRegularExpression::NoMatchOption 으로 설정됩니다.
이 객체는 hasMatch() 및 hasPartialMatch() 멤버 함수를 통해 일치하는 항목이 없다고 보고합니다.
QRegularExpressionMatch::QRegularExpressionMatch(const QRegularExpressionMatch &match)
주어진 match 의 결과를 복사하여 일치 결과를 생성합니다.
operator=()도 참조하세요 .
[noexcept, since 6.1]
QRegularExpressionMatch::QRegularExpressionMatch(QRegularExpressionMatch &&match)
주어진 match 에서 결과를 이동하여 일치 결과를 생성합니다.
QRegularExpressionMatch에서 이동한 것은 소멸하거나 할당할 수만 있습니다. 소멸자나 할당 연산자 중 하나가 아닌 다른 함수를 호출하는 효과는 정의되지 않았습니다.
이 함수는 Qt 6.1에 도입되었습니다.
operator=()도 참조하십시오 .
[noexcept]
QRegularExpressionMatch::~QRegularExpressionMatch()
경기 결과를 삭제합니다.
QString QRegularExpressionMatch::captured(QAnyStringView name) const
name 라는 이름의 캡처 그룹이 캡처한 하위 문자열을 반환합니다.
명명된 캡처 그룹 name 이 문자열을 캡처하지 않았거나 name 이라는 캡처 그룹이 없는 경우, null QString 을 반환합니다.
참고: 6.8 이전 Qt 버전에서는 이 함수는 QAnyStringView 가 아닌 QString 또는 QStringView 을 취했습니다.
capturedView(), capturedStart(), capturedEnd(), capturedLength() 및 QString::isNull()도 참조하십시오 .
QString QRegularExpressionMatch::captured(int nth = 0) const
nth 캡처 그룹이 캡처한 하위 문자열을 반환합니다.
nth 캡처 그룹이 문자열을 캡처하지 않았거나 해당 캡처 그룹이 없는 경우 null QString 을 반환합니다.
참고: 암시적 캡처 그룹 번호 0은 전체 패턴과 일치하는 하위 문자열을 캡처합니다.
capturedView(), lastCapturedIndex(), capturedStart(), capturedEnd(), capturedLength() 및 QString::isNull()도 참조하세요 .
qsizetype QRegularExpressionMatch::capturedEnd(QAnyStringView name) const
name 이라는 캡처 그룹에 의해 캡처된 하위 문자열의 끝 위치 바로 뒤에 있는 제목 문자열 내부의 오프셋을 반환합니다. name 라는 이름의 캡처 그룹이 문자열을 캡처하지 않았거나 존재하지 않으면 -1을 반환합니다.
참고: 6.8 이전 Qt 버전에서 이 함수는 QAnyStringView 이 아닌 QString 또는 QStringView 을 취했습니다.
capturedStart(), capturedLength() 및 captured()도 참조하십시오 .
qsizetype QRegularExpressionMatch::capturedEnd(int nth = 0) const
nth 캡처 그룹에서 캡처한 하위 문자열의 끝 위치 바로 뒤에 있는 제목 문자열 내부의 오프셋을 반환합니다. nth 캡처 그룹이 문자열을 캡처하지 않았거나 존재하지 않는 경우 -1을 반환합니다.
capturedStart(), capturedLength() 및 captured()도 참조하세요 .
qsizetype QRegularExpressionMatch::capturedLength(QAnyStringView name) const
name 라는 이름의 캡처 그룹이 캡처한 하위 문자열의 길이를 반환합니다.
참고: name 라는 이름의 캡처 그룹이 문자열을 캡처하지 않았거나 존재하지 않는 경우 이 함수는 0을 반환합니다.
참고: 6.8 이전 Qt 버전에서 이 함수는 QAnyStringView 이 아닌 QString 또는 QStringView 을 받습니다.
capturedStart(), capturedEnd() 및 captured()도 참조하세요 .
qsizetype QRegularExpressionMatch::capturedLength(int nth = 0) const
nth 캡처 그룹이 캡처한 하위 문자열의 길이를 반환합니다.
참고: nth 캡처 그룹이 문자열을 캡처하지 않았거나 존재하지 않는 경우 이 함수는 0을 반환합니다.
capturedStart(), capturedEnd() 및 captured()도 참조하세요 .
qsizetype QRegularExpressionMatch::capturedStart(QAnyStringView name) const
name 라는 캡처 그룹에서 캡처한 하위 문자열의 시작 위치에 해당하는 제목 문자열 내부의 오프셋을 반환합니다. name 라는 이름의 캡처 그룹이 문자열을 캡처하지 않았거나 존재하지 않으면 -1을 반환합니다.
참고: 6.8 이전 Qt 버전에서 이 함수는 QAnyStringView 이 아닌 QString 또는 QStringView 을 취했습니다.
capturedEnd(), capturedLength() 및 captured()도 참조하십시오 .
qsizetype QRegularExpressionMatch::capturedStart(int nth = 0) const
nth 캡처 그룹에서 캡처한 하위 문자열의 시작 위치에 해당하는 제목 문자열 내부의 오프셋을 반환합니다. nth 캡처 그룹이 문자열을 캡처하지 않았거나 존재하지 않는 경우 -1을 반환합니다.
capturedEnd(), capturedLength() 및 captured()도 참조하세요 .
QStringList QRegularExpressionMatch::capturedTexts() const
패턴 문자열에 그룹이 나타나는 순서대로 캡처 그룹으로 캡처한 모든 문자열의 목록을 반환합니다. 이 목록에는 전체 패턴과 일치하는 하위 문자열을 캡처하는 암시적 캡처 그룹 번호 0이 포함됩니다.
QStringView QRegularExpressionMatch::capturedView(QAnyStringView name) const
name 라는 이름의 캡처 그룹이 캡처한 문자열의 보기를 반환합니다.
명명된 캡처 그룹 name 이 문자열을 캡처하지 않았거나 name 이라는 캡처 그룹이 없는 경우 , null QStringView 을 반환합니다.
참고: 6.8 이전 Qt 버전에서는 이 함수는 QAnyStringView 가 아닌 QString 또는 QStringView 을 취했습니다.
captured(), capturedStart(), capturedEnd(), capturedLength() 및 QStringView::isNull()도 참조하십시오 .
QStringView QRegularExpressionMatch::capturedView(int nth = 0) const
nth 캡처 그룹이 캡처한 하위 문자열의 보기를 반환합니다.
nth 캡처 그룹이 문자열을 캡처하지 않았거나 그러한 캡처 그룹이 없는 경우 null QStringView 을 반환합니다.
참고: 암시적 캡처 그룹 번호 0은 전체 패턴과 일치하는 하위 문자열을 캡처합니다.
captured(), lastCapturedIndex(), capturedStart(), capturedEnd(), capturedLength() 및 QStringView::isNull()도 참조하세요 .
[since 6.3]
bool QRegularExpressionMatch::hasCaptured(QAnyStringView name) const
name 라는 이름의 캡처 그룹이 제목 문자열에 있는 내용을 캡처한 경우 참을 반환하고, 그렇지 않은 경우(또는 name 라는 캡처 그룹이 없는 경우) 거짓을 반환합니다.
참고: 정규식에 포함된 일부 캡처 그룹은 정규식이 일치하더라도 아무것도 캡처하지 못할 수 있습니다. 예를 들어 패턴에 조건부 연산자가 사용된 경우 이런 일이 발생할 수 있습니다:
QRegularExpression re("([a-z]+)|([A-Z]+)");QRegularExpressionMatch m = re.match("UPPERCASE");if (m.hasMatch()) { qDebug() << m.hasCaptured(0); // true qDebug() << m.hasCaptured(1); // false qDebug() << m.hasCaptured(2); // true
마찬가지로, 캡처 그룹은 길이 0의 부분 문자열을 캡처할 수 있으며, 이 함수는 이러한 캡처 그룹에 대해 true
을 반환합니다.
참고: 6.8 이전 Qt 버전에서 이 함수는 QAnyStringView 이 아닌 QString 또는 QStringView 을 받습니다.
이 함수는 Qt 6.3에 도입되었습니다.
captured() 및 hasMatch()도 참조하십시오 .
[since 6.3]
bool QRegularExpressionMatch::hasCaptured(int nth) const
nth 캡처 그룹이 제목 문자열에 있는 내용을 캡처한 경우 참을 반환하고, 그렇지 않은 경우(또는 해당 캡처 그룹이 없는 경우) 거짓을 반환합니다.
참고: 암시적 캡처 그룹 번호 0은 전체 패턴과 일치하는 하위 문자열을 캡처합니다.
참고: 정규식의 일부 캡처 그룹은 정규식이 일치하더라도 아무것도 캡처하지 않을 수 있습니다. 예를 들어 패턴에 조건부 연산자가 사용된 경우 이런 일이 발생할 수 있습니다:
QRegularExpression re("([a-z]+)|([A-Z]+)");QRegularExpressionMatch m = re.match("UPPERCASE");if (m.hasMatch()) { qDebug() << m.hasCaptured(0); // true qDebug() << m.hasCaptured(1); // false qDebug() << m.hasCaptured(2); // true
마찬가지로 캡처 그룹은 길이 0의 부분 문자열을 캡처할 수 있으며, 이 함수는 이러한 캡처 그룹에 대해 true
을 반환합니다.
이 함수는 Qt 6.3에 도입되었습니다.
captured(), lastCapturedIndex() 및 hasMatch()도 참조하십시오 .
bool QRegularExpressionMatch::hasMatch() const
정규식이 제목 문자열과 일치하면 true
, 그렇지 않으면 false를 반환합니다.
QRegularExpression::match() 및 hasPartialMatch()도 참조하세요 .
bool QRegularExpressionMatch::hasPartialMatch() const
정규식이 제목 문자열과 부분적으로 일치하면 true
을 반환하고, 그렇지 않으면 false를 반환합니다.
참고: 부분 일치 유형 중 하나를 명시적으로 사용한 일치만 부분 일치를 산출할 수 있습니다. 하지만 이러한 일치가 완전히 성공하면 이 함수는 거짓을 반환하고 hasMatch()는 참을 반환합니다.
QRegularExpression::match(), QRegularExpression::MatchType, hasMatch()도 참조하세요 .
bool QRegularExpressionMatch::isValid() const
유효한 QRegularExpression 객체에서 호출된 QRegularExpression::match() 함수의 결과로 일치 객체를 얻은 경우 true
를 반환하고, QRegularExpression 가 유효하지 않은 경우 false
를 반환합니다.
QRegularExpression::match() 및 QRegularExpression::isValid()도 참조하세요 .
int QRegularExpressionMatch::lastCapturedIndex() const
암시적 캡처 그룹 0을 포함하여 무언가를 캡처한 마지막 캡처 그룹의 인덱스를 반환합니다. 이 인덱스를 사용하여 캡처된 모든 하위 문자열을 추출할 수 있습니다:
QRegularExpressionMatch match = re.match(string); for (int i = 0; i <= match.lastCapturedIndex(); ++i) { QString captured = match.captured(i); // ... }
마지막CapturedIndex()보다 작은 인덱스를 가진 일부 캡처 그룹은 일치하지 않았을 수 있으므로 아무것도 캡처하지 않았을 수 있습니다.
정규식이 일치하지 않으면 이 함수는 -1을 반환합니다.
hasCaptured(), captured(), capturedStart(), capturedEnd(), capturedLength()도 참조하세요 .
QRegularExpression::MatchOptions QRegularExpressionMatch::matchOptions() const
이 QRegularExpressionMatch 객체를 가져오는 데 사용된 일치 옵션, 즉 QRegularExpression::match() 또는 QRegularExpression::globalMatch()에 전달된 일치 옵션을 반환합니다.
QRegularExpression::match(), regularExpression() 및 matchType()도 참조하세요 .
QRegularExpression::MatchType QRegularExpressionMatch::matchType() const
이 QRegularExpressionMatch 객체를 가져오는 데 사용된 일치 유형, 즉 QRegularExpression::match() 또는 QRegularExpression::globalMatch()에 전달된 일치 유형을 반환합니다.
QRegularExpression::match(), regularExpression() 및 matchOptions()도 참조하세요 .
QRegularExpression QRegularExpressionMatch::regularExpression() const
match() 함수가 이 객체를 반환한 QRegularExpression 객체를 반환합니다.
QRegularExpression::match(), matchType() 및 matchOptions()도 참조하세요 .
[noexcept]
void QRegularExpressionMatch::swap(QRegularExpressionMatch &other)
이 일치 결과를 other 로 바꿉니다. 이 작업은 매우 빠르며 실패하지 않습니다.
[noexcept]
QRegularExpressionMatch &QRegularExpressionMatch::operator=(QRegularExpressionMatch &&match)
이동 - 일치 결과 match 를 이 개체에 할당하고 결과에 대한 참조를 반환합니다.
QRegularExpressionMatch 에서 이동한 객체는 소멸하거나 할당할 수만 있습니다. 소멸자 또는 할당 연산자 중 하나가 아닌 다른 함수를 호출하는 효과는 정의되지 않았습니다.
QRegularExpressionMatch &QRegularExpressionMatch::operator=(const QRegularExpressionMatch &match)
일치 결과 match 를 이 객체에 할당하고 사본에 대한 참조를 반환합니다.
관련 비회원
QDebug operator<<(QDebug debug, const QRegularExpressionMatch &match)
디버깅을 위해 일치 객체 match 를 디버그 객체 debug 에 씁니다.
디버깅 기법도참조하세요 .
© 2025 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.