# **[](https://en.cppreference.com/w/cpp/header/regex)** provides regular expression matching via `std::regex`, `std::regex_match`, `std::regex_search`, and `std::regex_replace`. The syntax defaults to ECMAScript (JavaScript-like) regex. C++ regex is slower than dedicated libraries like `oniguruma` or `PCRE2`, but is portable and does not require external dependencies. ## Example This example searches for a regex pattern in a string and performs a regex-based replacement to modify text. ```cpp // compile: g++ -std=c++11 -o regexexample regexexample.cpp // run: ./regexexample // description: regex matching and replacement #include #include #include int main() { std::string text = "hello world"; std::regex pattern("l+o"); if (std::regex_search(text, pattern)) { std::cout << "found match\n"; } std::string result = std::regex_replace(text, pattern, "X"); std::cout << "after replace: " << result << "\n"; return 0; } ```