regex - 我可以在 char16_t 字符串上使用 STL 正则表达式库吗?

标签 regex c++11 stl char16-t

简而言之,以下代码本质上有什么问题?

#include <regex>
int main() {
    std::regex_match(u" ", std::basic_regex<char16_t>{u" "});
}

它的错误

$ g++ -std=c++17 main.cpp -o main
$ ./main
terminate called after throwing an instance of 'std::bad_cast'
  what():  std::bad_cast
Aborted (core dumped)

更多信息:

$ g++ --version                                                                                                                                                                                                                                    
g++ (GCC) 10.2.0                                                                                                                                                                                                                                               
Copyright (C) 2020 Free Software Foundation, Inc.                                                                                                                                                                                                              
This is free software; see the source for copying conditions.  There is NO                                                                                                                                                                                     
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

最佳答案

C++ 标准库不支持 char16_t 或 char32_t Unicode 的正则表达式。有一个提案可以解决这个问题,但它不在 C++20 中:http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0169r0.html

关于regex - 我可以在 char16_t 字符串上使用 STL 正则表达式库吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64007157/

相关文章:

c++ - 如何使派生类函数作为线程的启动例程?

c++ - 将双端队列与 C 库一起使用

c# - 检查数字中的数字是否按升序排列

regex - sed 替换星号

javascript - 正则表达式 : Why this regex doesn't match "not starts with" two letter?

c++ - 这是 std::bitset::operator^= 和 std::bitset::count 的正常行为吗?如果是这样,为什么?

python - 如何在 Python 正则表达式中验证 unicode "word characters"?

c++ - 为什么 `std::enable_if` 需要默认值?

c++ - STL克隆载体

c++ - 排列对象 vector 的最佳实践