How to validate HTML tag using Regular Expression | C ++ program to validate the HTML tag using Regular Expression ; Function to validate the HTML tag . ; Regex to check valid HTML tag . ; If the HTML tag is empty return false ; Return true if the HTML tag matched the ReGex ; Driver Code ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 : ; Test Case 5 :
#include <iostream> NEW_LINE #include <regex> NEW_LINE using namespace std ; bool isValidHTMLTag ( string str ) { const regex pattern ( " < ( \" [ ^ \" ] * \" ▁ ' [ ^ ' ] * ' ▁ [ ^ ' \" > ] ) * > " ) ; if ( str . empty ( ) ) { return false ; } if ( regex_match ( str , pattern ) ) { return true ; } else { return false ; } } int main ( ) { string str1 = " < input ▁ value ▁ = ▁ ' > ' > " ; cout << isValidHTMLTag ( str1 ) << endl ; string str2 = " < br / > " ; cout << isValidHTMLTag ( str2 ) << endl ; string str3 = " br / > " ; cout << isValidHTMLTag ( str3 ) << endl ; string str4 = " < ' br / > " ; cout << isValidHTMLTag ( str4 ) << endl ; string str5 = " < input ▁ value ▁ = > ▁ > " ; cout << isValidHTMLTag ( str5 ) << endl ; return 0 ; }