I have worked with regex in my project in c# and it behaved as expected. I moved the regex to c++ and the regex gave always false, even with a valid string I created.
// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"
#include <iostream>
#include <string>
#include <regex>
#include <cstring> // For memset
extern "C" __declspec(dllexport) bool ValidateWithRegex(const char* input, int length, const char* pattern)
{
// Convert the byte array (UTF-8 encoded) into a std::string
// std::string inputStr(input, length); // Convert char* (UTF-8) to std::string
std::string utf8String = "123312";
// std::string utf8String(input);
// Create the regex object with the passed pattern
std::regex regexPattern("^[a-zA-Z0-9\\W]{6,6}$");
// Check if the input value matches the regex pattern
bool isValid = std::regex_match(utf8String, regexPattern);
// After validation, overwrite the string buffer
std::memset(&utf8String[0], 0, utf8String.size()); // Overwrites the internal memory of the string
return isValid;
}
When I call ValidateWithRegex the output is always false. I have checked the input data is valid and correct and Trimd . I tested all steps before and found no mistakes but the output of regex is not working