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

前端 未结 1 697
萌比男神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
    std::size_t countMatches(const CharT* find, const CharT* str)
    {
        std::basic_string text(str);
        std::basic_regex reg(find);
        typedef typename std::basic_string::iterator iter_t;
        return distance(std::regex_iterator(text.begin(), text.end(), reg),
                        std::regex_iterator());
    }
    

    0 讨论(0)
提交回复
热议问题