diff --git a/plugins/base/utils/text-helpers.cpp b/plugins/base/utils/text-helpers.cpp index 8ab9450f..024826e4 100644 --- a/plugins/base/utils/text-helpers.cpp +++ b/plugins/base/utils/text-helpers.cpp @@ -1,15 +1,12 @@ #include "text-helpers.hpp" -#include +#include namespace advss { -QString EscapeForRegex(const QString &s) +QString EscapeForRegex(const QString &input) { - static std::regex specialChars{R"([-[\]{}()*+?.,\^$|#\s])"}; - std::string input = s.toStdString(); - return QString::fromStdString( - std::regex_replace(input, specialChars, R"(\$&)")); + return QRegularExpression::escape(input); } } // namespace advss diff --git a/tests/test-regex.cpp b/tests/test-regex.cpp index 52ac4a61..becc3b22 100644 --- a/tests/test-regex.cpp +++ b/tests/test-regex.cpp @@ -80,11 +80,3 @@ TEST_CASE("Matches (PartialMatchRegexConfig)", "[regex-config]") result = regex.Matches(std::string("abc"), "a"); REQUIRE(result == true); } - -TEST_CASE("EscapeForRegex , [text-helpers]") -{ - REQUIRE(advss::EscapeForRegex("") == ""); - REQUIRE(advss::EscapeForRegex("abcdefg") == "abcdefg"); - REQUIRE(advss::EscapeForRegex("(abcdefg)") == "\\(abcdefg\\)"); - REQUIRE(advss::EscapeForRegex("\\(abcdefg)") == "\\\\(abcdefg\\)"); -}