C++ count matches regex function that works with both char and wchar_t?

前端 未结 1 711
萌比男神i
萌比男神i 2021-01-24 19:53

With the answer from this question I was able to create a function that uses regex to find and replace in strings that works with both char and wchar_t

    templ         


        
相关标签:
1条回答
  • 2021-01-24 20:42

    std::regex_iterator is a class template too

    template<typename CharT>
    std::size_t countMatches(const CharT* find, const CharT* str)
    {
        std::basic_string<CharT> text(str);
        std::basic_regex<CharT> reg(find);
        typedef typename std::basic_string<CharT>::iterator iter_t;
        return distance(std::regex_iterator<iter_t>(text.begin(), text.end(), reg),
                        std::regex_iterator<iter_t>());
    }
    
    0 讨论(0)
提交回复
热议问题