unicode regex C++

How do i use c++ regex with unicode string?
On windows, there is a error "regex directory is not found". <regex.h> is unix library?
<regex> is the standard C++ header.

However, if you are using the GNU implementation, there is a problem: GCC is non-conforming.

With the Microsoft compiler, UTF-8:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <string>
#include <regex>
#include <locale>

int main()
{
    {
        std::locale::global(  std::locale("English_UK") ) ;

        const std::regex pattern( "\xA3[[:digit:]]+", std::regex_constants::extended ) ;
        const std::string str = "abcd\xA3""1234efgh\xA9""ijkl" ;
        if( std::regex_search( str, pattern) ) std::cout << "ok\n" ;

        std::locale::global( std::locale() ) ;
    }
}


With the GNU compiler, boost regex and fall back to wchar_t
(GCC doesn't have any locale support either):
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <string>
#include <boost/regex.hpp> // boost instead of standard
#include <locale>

int main()
{
    const boost::wregex pattern( L"\xA3[[:digit:]]+", boost::regex_constants::extended ) ;
    const std::wstring str = L"abcd\xA3""1234efgh\xA9""ijkl" ;
    if( boost::regex_search( str, pattern) ) std::cout << "ok\n" ;

    // http://liveworkspace.org/code/1YwkDu$0
}
I am using eclipse as an IDE for C++ programming and compiler is WinGCC.
How do you install boots library for Eclipse ?
Last edited on
Topic archived. No new replies allowed.