String matching in C++ can't get the correct result, but in java can Java code is as follows
String txt = " static char k_a123[] = \"fefeffefefwefwef/fefe/f/ef/ef\\0\"; int fefefefefeeffef = 123; static char k_a123233[] = \"fef/efef/efef\\0\"; int fwefnewff=21323; static char k_a1233334[] = \"<init>\\0\"; static char k_a123555[] = \"fefefef)fefe/fef/V\\0\"; addAll(123,333);";
String reg = "\\sstatic\\schar\\sk_\\S+\\s=";
Pattern p = Pattern.compile(reg, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
Matcher m = p.matcher(txt);
while (m.find()) {
for (int i = 0; i <= m.groupCount(); i++) {
System.out.println(" ===== " + m.group(i));
}
}
// fowllow is outpu result
// ===== static char k_a123[] =
// ===== static char k_a123233[] =
// ===== static char k_a1233334[] =
// ===== static char k_a123555[] =
C++ code is as follows
std::string s1 = " static char k_a123[] = \"fefeffefefwefwef/fefe/f/ef/ef\\0\"; int fefefefefeeffef = 123; static char k_a123233[] = \"fef/efef/efef\\0\"; int fwefnewff=21323; static char k_a1233334[] = \"<init>\\0\"; static char k_a123555[] = \"fefefef)fefe/fef/V\\0\"; addAll(123,333);";
std::string reee = "\\sstatic\\schar\\sk_\\S+\\s="; // Double Quote String 4
std::string xxx(reee);
std::regex rgx(xxx);
std::smatch match;
std::regex_search(s1, match, rgx);
for (uint32_t index = 0; index < match.size(); index++)
{
printf("bbb [%d] %s\n", index, std::string(match[index]).c_str());
}
// xcode output
// bbbb [0] static char k_v1[] =
// bbbb [1]
/********* xcode output over ,nothing...... why? *******************/
I think it's because c++ truncates the string using \0, and java matches the correct result. C++ uses xcode to run code What can I do to get the same result for java and c++?
These 2 parts of the code can be copied and run directly, but the java output is correct. C++ is incorrect. How to make them output the same result.