Программы на C++. Форум разработчиков
-
Anonymous
C++ std::regex неожиданно соответствует символам UTF-8
Сообщение
Anonymous »
Я столкнулся с неожиданным поведением std::regex при сопоставлении строк, содержащих символы UTF-8.
Код: Выделить всё
#include
#include
#include
bool matchPattern(const std::string& str) {
// Regular expression pattern
std::string pattern = R"(^[a-zA-Z0-9,.!?;:,。!?'"()\[\]_{}\-*…✓ ]+$)";
// Create regex object
std::regex regexPattern(pattern);
// Check if matches
return std::regex_match(str, regexPattern);
}
int main() {
std::string data1 = "「"; // Chinese left quotation mark (UTF-8)
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79802693/c-stdregex-matches-utf-8-characters-unexpectedly[/url]
1761648990
Anonymous
Я столкнулся с неожиданным поведением std::regex при сопоставлении строк, содержащих символы UTF-8.
[code]#include
#include
#include
bool matchPattern(const std::string& str) {
// Regular expression pattern
std::string pattern = R"(^[a-zA-Z0-9,.!?;:,。!?'"()\[\]_{}\-*…✓ ]+$)";
// Create regex object
std::regex regexPattern(pattern);
// Check if matches
return std::regex_match(str, regexPattern);
}
int main() {
std::string data1 = "「"; // Chinese left quotation mark (UTF-8)
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79802693/c-stdregex-matches-utf-8-characters-unexpectedly[/url]