Check three or more consecutive identical characters or numbers | C ++ program to check three or more consecutive identical characters or numbers using Regular Expression ; Function to check three or more consecutive identical characters or numbers . ; Regex to check valid three or more consecutive identical characters or numbers . ; If the three or more consecutive identical characters or numbers is empty return false ; Return true if the three or more consecutive identical characters or numbers 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 isIdentical ( string str ) { const regex pattern ( " \\ b ( [ a - zA - Z0-9 ] ) \\ 1 \\ 1 + \\ b " ) ; if ( str . empty ( ) ) { return false ; } if ( regex_match ( str , pattern ) ) { return true ; } else { return false ; } } int main ( ) { string str1 = " aaa " ; cout << isIdentical ( str1 ) << endl ; string str2 = "11111" ; cout << isIdentical ( str2 ) << endl ; string str3 = " aaab " ; cout << isIdentical ( str3 ) << endl ; string str4 = " abc " ; cout << isIdentical ( str4 ) << endl ; string str5 = " aa " ; cout << isIdentical ( str5 ) << endl ; return 0 ; }