Leggere in inglese

Condividi tramite


Funzione regex_search

Cerca una corrispondenza di espressione regolare.

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);

Parametri

  • BidIt
    Il tipo di iteratore per le sottocorrispondenze.

  • Alloc
    La classe di allocatore di risultati match.

  • Elem
    Il tipo di elementi da ricercare.

  • RXtraits
    Classe di tratti per gli elementi.

  • Alloc2
    La classe di allocatore di espressione regolare.

  • IOtraits
    La classe di tratti della stringa.

  • IOalloc
    La classe di allocatore della stringa.

  • flags
    Flag per le corrispondenze.

  • first
    Inizio di sequenza da ricercare.

  • last
    Fine della sequenza da ricercare.

  • match
    I risultati match.

  • ptr
    Puntatore all'avvio di una sequenza da ricercare.

  • re
    L'espressione regolare da ricercare.

  • str
    Stringa da ricercare.

Note

Ogni funzione di modello restituirà true solo se una ricerca del relativo argomento re di espressione regolare nella relativa sequenza di operando ha esito positivo. Le funzioni che accettano un oggetto di match_results impostano i relativi membri per riflettere se la ricerca ha avuto esito positivo e in caso positivo quali le diverse acquisizione raggruppa nell'espressione regolare acquisita.

Esempio

 

// std_tr1__regex__regex_search.cpp 
// compile with: /EHsc 
#include <regex> 
#include <iostream> 
 
int main() 
    { 
    const char *first = "abcd"; 
    const char *last = first + strlen(first); 
    std::cmatch mr; 
    std::regex rx("abc"); 
    std::regex_constants::match_flag_type fl = 
        std::regex_constants::match_default; 
 
    std::cout << "search(f, f+1, \"abc\") == " << std::boolalpha 
        << regex_search(first, first + 1, rx, fl) << std::endl; 
 
    std::cout << "search(f, l, \"abc\") == " << std::boolalpha 
        << regex_search(first, last, mr, rx) << std::endl; 
    std::cout << "  matched: \"" << mr.str() << "\"" << std::endl; 
 
    std::cout << "search(\"a\", \"abc\") == " << std::boolalpha 
        << regex_search("a", rx) << std::endl; 
 
    std::cout << "search(\"xabcd\", \"abc\") == " << std::boolalpha 
        << regex_search("xabcd", mr, rx) << std::endl; 
    std::cout << "  matched: \"" << mr.str() << "\"" << std::endl; 
 
    std::cout << "search(string, \"abc\") == " << std::boolalpha 
        << regex_search(std::string("a"), rx) << std::endl; 
 
    std::string str("abcabc"); 
    std::match_results<std::string::const_iterator> mr2; 
    std::cout << "search(string, \"abc\") == " << std::boolalpha 
        << regex_search(str, mr2, rx) << std::endl; 
    std::cout << "  matched: \"" << mr2.str() << "\"" << std::endl; 
 
    return (0); 
    } 
 
  

Requisiti

Intestazione: <regex>

Spazio dei nomi: std

Vedere anche

Riferimenti

<regex>

Funzione regex_match

Funzione regex_replace