Skip to content

Instantly share code, notes, and snippets.

@Cryolitia
Last active October 12, 2023 12:59
Show Gist options
  • Save Cryolitia/10424e4c5a1fc9ec9e1e3f3fbfb1a6bd to your computer and use it in GitHub Desktop.
Save Cryolitia/10424e4c5a1fc9ec9e1e3f3fbfb1a6bd to your computer and use it in GitHub Desktop.
Regex single UTF-8 Character in std::string
#include <iostream>
#include <regex>
int main() {
std::string input = "你好,world!";
std::smatch matches;
auto regex = std::regex("([\\x00-\\x7F]|([\\xC0-\\xF7][\\x80-\\xBF]*))");
std::sregex_iterator begin(input.begin(),input.end(),regex);
std::sregex_iterator end;
for (auto i = begin;i!=end;++i) {
std::cout<<"Match: "<<i->str()<<std::endl;
}
return 0;
}
@Cryolitia
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment