-
[c++] regex_search 함수카테고리 없음 2023. 1. 20. 13:52728x90
1.함수 헤더 파일
#include <regex>
2.함수 원형
template <class BidIt, class Alloc, class Elem, class RXtraits, class Alloc2> bool regex_search( BidIt first, Bidit last, match_results<BidIt, Alloc>& match, const basic_regex<Elem, RXtraits, Alloc2>& re, match_flag_type flags = match_default); template <class BidIt, class Elem, class RXtraits, class Alloc2> bool regex_search( BidIt first, Bidit last, const basic_regex<Elem, RXtraits, Alloc2>& re, match_flag_type flags = match_default); template <class Elem, class Alloc, class RXtraits, class Alloc2> bool regex_search( const Elem* ptr, match_results<const Elem*, Alloc>& match, const basic_regex<Elem, RXtraits, Alloc2>& re, match_flag_type flags = match_default); template <class Elem, class RXtraits, class Alloc2> bool regex_search( const Elem* ptr, const basic_regex<Elem, RXtraits, Alloc2>& re, match_flag_type flags = match_default); template <class IOtraits, class IOalloc, class Alloc, class Elem, class RXtraits, class Alloc2> bool regex_search( const basic_string<Elem, IOtraits, IOalloc>& str, match_results<typename basic_string<Elem, IOtraits, IOalloc>::const_iterator, Alloc>& match, const basic_regex<Elem, RXtraits, Alloc2>& re, match_flag_type flags = match_default); template <class IOtraits, class IOalloc, class Elem, class RXtraits, class Alloc2> bool regex_search( const basic_string<Elem, IOtraits, IOalloc>& str, const basic_regex<Elem, RXtraits, Alloc2>& re, match_flag_type flags = match_default);
3. Parameter (매개 변수)
BidIt The iterator type for submatches. Alloc The match result allocator class. Elem The type of element to find a match for. RXtraits The attribute class for the element. Alloc2 The regular expression allocator class. IOtraits A string attribute class. IOalloc String allocator class. flags Flags for matching. first The start of the matching sequence. last End of matching sequence. match Match result. ptr A pointer to the start of the matching sequence. re The regular expression to look for matches. str A string to match. 4. Described
re : 각 템플릿 함수는 피연산자 시퀀스에서 해당 정규식 인수 검색이 성공한 경우에만 true를 반환합니다.
match result : 개체를 가져오는 함수는 검색이 성공했는지 여부를 반영하도록 구성원을 설정하고, 성공한 경우 정규식의 다양한 캡처 그룹을 캡처합니다.
4.예제
#include <iostream> #include <regex> using namespace std; int main(){ const char *first = "abcd"; const char *last = first + strlen(first); cmatch mr; regex_constants::match_flag_type f1 = regex_constants::match_default; regex rx("abc"); cout << "search(f, f+1, \"abc\") == " << boolalpha << regex_search(first, first + 1, rx, f1) <<endl; cout << "search(f, l, \"abc\") == " << boolalpha << regex_search(first, last, mr, rx) <<endl; cout << " matched: \"" << mr.str() << "\"" << endl; cout << "search(string, \"abc\") == " << boolalpha << regex_search(string("a"), rx) << endl; string str("abcabc"); match_results<string::const_iterator> mr2; cout << "search(string, \"abc\") == " << boolalpha << regex_search(str, mr2, rx) << endl; cout << " matched \"" << mr2.str() << "\"" << endl; }
search(f, f+1, "abc") == false search(f, l, "abc") == true matched: "abc" search(string, "abc") == false search(string, "abc") == true matched "abc"
728x90