C++ (Qt)#include <iostream>#include <boost/tokenizer.hpp>#include <string> using namespace boost; int main(){ std::string s = "Мама, глядя, сказала: \"твою мать\" \\n и ушла."; escaped_list_separator<char> sep("\\", ":,", "\""); tokenizer<escaped_list_separator<char>> tok(s, sep); for(const auto & res : tok) { std::cout << res << std::endl; } return 0;}
escaped_list_separator<char> sep("\\", " :,", "\"");
std::string s = "Мама, глядя, сказала: \"твою мать\" \\r и ушла";
(?<=").+(?=")|\b\w+\b
import Foundationlet p = #"(?<=").+(?=")|\b\w+\b"#let re = try! NSRegularExpression(pattern: p, options: [])let s = "Мама, глядя, сказала: \"твою мать\"\n и ушла."for match in re.matches(in: s, range: NSRange(location: 0, length: s.count)) { print((s as NSString).substring(with: match.range))}
int main(){ std::string s = "str1 \"str2 'str3 str4' str5\" str6"; escaped_list_separator<char> sep("\\", " ", "\"'"); tokenizer<escaped_list_separator<char>> tok(s, sep); for (const auto & res : tok) std::cout << res << std::endl; return 0;}
C++ (Qt)#include <iostream>#include <boost/tokenizer.hpp>#include "spec_token_functions.h" int main(){ std::string str = "str1 \"str2 'str3 str4' str5\" str6"; quote_list<char> quotes('\'', '\''); quotes.add_quote('"', '"'); std::string dropped_delims = " "; std::string kept_delims = ""; boost::tokenizer<spec_char_separator<char>> tok(str, spec_char_separator<char>(dropped_delims, kept_delims, quotes)); for (auto s : tok) std::cout << s << std::endl; return 0;}
Bashstr1"str2 'str3 str4' str5"str6