![]() |
Regular expressions or what we can call regex for short are sequences of symbols and characters that create a search pattern and help us to find specific patterns within a given text. In this article, we will learn how to replace text in a string using regex in C++. Example Input: str = "Hello, World! Hello, GFG!" ; text = "Hello"; replace= "Hi"; Output: Hi, World! Hi, GFG! Replace Regex Matches in C++ StringTo replace a text in a string using regex, we can use the function std::regex_replace(). It is defined inside the <regex> header so we need to include it in our program. Algorithm1. Define the main string, string to be replaced and replacement string. C++ Program to Replace Text in a String Using RegexC++
Output
Original: Hello, World! Hello, GFG! Modified: Hi, World! Hi, GFG! Time Complexity: O(N) |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 15 |