Program to remove HTML tags from a given String | C ++ program for the above approach ; Function to remove the HTML tags from the given string ; Use regex_replace function in regex to erase every tags enclosed in < > ; Print string after removing tags ; Driver Code ; Given String ; Function call to print the HTML string after removing tags
#include <iostream> NEW_LINE #include <regex> NEW_LINE using namespace std ; void RemoveHTMLTags ( string s ) { const regex pattern ( " \\ < . * ? \\ > " ) ; s = regex_replace ( s , pattern , " " ) ; cout << s ; return ; } int main ( ) { string str = " < div > < b > Geeks ▁ for ▁ Geeks < / b > < / div > " ; RemoveHTMLTags ( str ) ; return 0 ; }