[c++] 정규 표현식을 사용한 특정 패턴 매치 여부 확인
아래는 간단한 예제 코드입니다.
#include <iostream>
#include <regex>
int main() {
std::string text = "This is a sample text with pattern to match.";
std::regex pattern("pattern");
if (std::regex_search(text, pattern)) {
std::cout << "Pattern found in the text." << std::endl;
} else {
std::cout << "Pattern not found in the text." << std::endl;
}
return 0;
}
위 코드에서는 “This is a sample text with pattern to match.”라는 문자열에서 “pattern”이라는 패턴이 존재하는지 확인하고 있습니다.
더 복잡한 정규 표현식을 사용하여 다양한 패턴을 매치하는 방법에 대해서는 C++ 정규 표현식 문서를 참고할 수 있습니다.
참고:
- C++ 정규 표현식 문서: https://en.cppreference.com/w/cpp/regex
메시지의 문맥은 중요하게 작용합니다. 제공된 정보가 충분한지 확인하고, 더 깊은 정보를 제공하도록 요청해주세요.