Regular Expressions 101

Save & Share

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8
  • .NET 7.0 (C#)
  • Rust
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests

Tools

Sponsors
There are currently no sponsors. Become a sponsor today!
An explanation of your regex will be automatically generated as you type.
Detailed match information will be displayed here automatically.
  • All Tokens
  • Common Tokens
  • General Tokens
  • Anchors
  • Meta Sequences
  • Quantifiers
  • Group Constructs
  • Character Classes
  • Flags/Modifiers
  • Substitution
  • A single character of: a, b or c
    [abc]
  • A character except: a, b or c
    [^abc]
  • A character in the range: a-z
    [a-z]
  • A character not in the range: a-z
    [^a-z]
  • A character in the range: a-z or A-Z
    [a-zA-Z]
  • Any single character
    .
  • Alternate - match either a or b
    a|b
  • Any whitespace character
    \s
  • Any non-whitespace character
    \S
  • Any digit
    \d
  • Any non-digit
    \D
  • Any word character
    \w
  • Any non-word character
    \W
  • Non-capturing group
    (?:...)
  • Capturing group
    (...)
  • Zero or one of a
    a?
  • Zero or more of a
    a*
  • One or more of a
    a+
  • Exactly 3 of a
    a{3}
  • 3 or more of a
    a{3,}
  • Between 3 and 6 of a
    a{3,6}
  • Start of string
    ^
  • End of string
    $
  • A word boundary
    \b
  • Non-word boundary
    \B

Regular Expression

/
/
gm

Test String

Code Generator

Generated Code

#include <StringConstants.au3> ; to declare the Constants of StringRegExp #include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate Local $sRegex = "(?m)back up code" Local $sString = "//9-digits phone number" & @CRLF & _ "#include<iostream>" & @CRLF & _ "#include<regex>" & @CRLF & _ "#include <string>" & @CRLF & _ "#include <stdexcept>" & @CRLF & _ "using namespace std;" & @CRLF & _ "int main()" & @CRLF & _ "{" & @CRLF & _ " int n;" & @CRLF & _ " string s;" & @CRLF & _ " cin >> n;" & @CRLF & _ " getline(cin,s);" & @CRLF & _ " while(n--){" & @CRLF & _ " regex phone10("09[0-9]{2}(\\.[0-9]{3}){2}");" & @CRLF & _ " string st;" & @CRLF & _ " getline(cin, st);" & @CRLF & _ " if(regex_match(st, phone10))" & @CRLF & _ " cout << "Valid!" << endl;" & @CRLF & _ " else" & @CRLF & _ " cout << "Invalid!" << endl;" & @CRLF & _ " }" & @CRLF & _ " " & @CRLF & _ " return 0;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "//11 digits phone number" & @CRLF & _ "#include<iostream>" & @CRLF & _ "#include<regex>" & @CRLF & _ "#include <string>" & @CRLF & _ "#include <stdexcept>" & @CRLF & _ "using namespace std;" & @CRLF & _ "int main()" & @CRLF & _ "{" & @CRLF & _ " regex phone10("01[0-9]{9}");" & @CRLF & _ " string st;" & @CRLF & _ " int n;" & @CRLF & _ " cin >> n;" & @CRLF & _ " getline(cin,st);" & @CRLF & _ " while(n--){" & @CRLF & _ " getline(cin, st);" & @CRLF & _ " if(regex_match(st, phone10))" & @CRLF & _ " cout << "Valid!" << endl;" & @CRLF & _ " else" & @CRLF & _ " cout << "Invalid!" << endl;" & @CRLF & _ " }" & @CRLF & _ " " & @CRLF & _ " return 0;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "//alphabet string" & @CRLF & _ "#include<iostream>" & @CRLF & _ "#include<regex>" & @CRLF & _ "#include <string>" & @CRLF & _ "#include <stdexcept>" & @CRLF & _ "using namespace std;" & @CRLF & _ "int main()" & @CRLF & _ "{" & @CRLF & _ " regex pattern("[a-zA-Z\\s]+");" & @CRLF & _ " string st;" & @CRLF & _ " int n;" & @CRLF & _ " cin >> n;" & @CRLF & _ " getline(cin,st);" & @CRLF & _ " while(n--){" & @CRLF & _ " getline(cin, st);" & @CRLF & _ " if(regex_match(st, pattern))" & @CRLF & _ " cout << "Valid!" << endl;" & @CRLF & _ " else" & @CRLF & _ " cout << "Invalid!" << endl;" & @CRLF & _ " }" & @CRLF & _ " " & @CRLF & _ " return 0;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "//Alpha-numberic Strings With Limited Length" & @CRLF & _ "#include<iostream>" & @CRLF & _ "#include<regex>" & @CRLF & _ "#include <string>" & @CRLF & _ "#include <stdexcept>" & @CRLF & _ "using namespace std;" & @CRLF & _ "int main()" & @CRLF & _ "{" & @CRLF & _ " regex pattern("[a-z0-9]{6,20}");" & @CRLF & _ " string st;" & @CRLF & _ " int n;" & @CRLF & _ " cin >> n;" & @CRLF & _ " getline(cin,st);" & @CRLF & _ " while(n--){" & @CRLF & _ " getline(cin, st);" & @CRLF & _ " if(regex_match(st, pattern))" & @CRLF & _ " cout << "Valid!" << endl;" & @CRLF & _ " else" & @CRLF & _ " cout << "Invalid!" << endl;" & @CRLF & _ " }" & @CRLF & _ " " & @CRLF & _ " return 0;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "//bound checking for a Product" & @CRLF & _ "#include <stdio.h>" & @CRLF & _ "#include <stdlib.h>" & @CRLF & _ "#include <limits.h>" & @CRLF & _ "" & @CRLF & _ "int main()" & @CRLF & _ "{" & @CRLF & _ " unsigned int a,b;" & @CRLF & _ " scanf("%u%u",&a,&b);" & @CRLF & _ " if(a!=0 && b!=0 && UINT_MAX/a<b)" & @CRLF & _ " printf("No");" & @CRLF & _ " else" & @CRLF & _ " printf("Yes");" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "//bound checking for a Signed Product" & @CRLF & _ "#include <stdio.h>" & @CRLF & _ "#include <stdlib.h>" & @CRLF & _ "#include <limits.h>" & @CRLF & _ "" & @CRLF & _ "int main()" & @CRLF & _ "{" & @CRLF & _ " int a,b;" & @CRLF & _ " scanf("%d%d",&a,&b);" & @CRLF & _ " if(a>0&&b>0){" & @CRLF & _ " if(INT_MAX/a<b)" & @CRLF & _ " printf("No");" & @CRLF & _ " else" & @CRLF & _ " printf("Yes");" & @CRLF & _ " }" & @CRLF & _ " else if(a<0&&b<0){" & @CRLF & _ " if(INT_MAX/b>a)" & @CRLF & _ " printf("No");" & @CRLF & _ " else" & @CRLF & _ " printf("Yes");" & @CRLF & _ " }" & @CRLF & _ " else if(a>0&&b<0){" & @CRLF & _ " if(INT_MIN/a>b)" & @CRLF & _ " printf("No");" & @CRLF & _ " else" & @CRLF & _ " printf("Yes");" & @CRLF & _ " }" & @CRLF & _ " else if(a<0&&b>0){" & @CRLF & _ " if(INT_MIN/b>a)" & @CRLF & _ " printf("No");" & @CRLF & _ " else" & @CRLF & _ " printf("Yes");" & @CRLF & _ " }" & @CRLF & _ " else" & @CRLF & _ " printf("Yes");" & @CRLF & _ "" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "//bound checking for a Signed sum" & @CRLF & _ "#include <stdio.h>" & @CRLF & _ "#include <stdlib.h>" & @CRLF & _ "#include <limits.h>" & @CRLF & _ "" & @CRLF & _ "int main()" & @CRLF & _ "{" & @CRLF & _ " int a,b;" & @CRLF & _ " scanf("%d%d",&a,&b);" & @CRLF & _ " if(a>0 && b>0 && b>INT_MAX-a)" & @CRLF & _ " printf("No");" & @CRLF & _ " else if(a<0 && b<0 && b<INT_MIN-a)" & @CRLF & _ " printf("No");" & @CRLF & _ " else" & @CRLF & _ " printf("Yes");" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "//Bound checking for a Sum" & @CRLF & _ "#include <stdio.h>" & @CRLF & _ "#include <stdlib.h>" & @CRLF & _ "#include <limits.h>" & @CRLF & _ "" & @CRLF & _ "int main()" & @CRLF & _ "{" & @CRLF & _ " unsigned int a,b;" & @CRLF & _ " scanf("%u%u",&a,&b);" & @CRLF & _ " if(UINT_MAX-a>=b)" & @CRLF & _ " printf("Yes");" & @CRLF & _ " else" & @CRLF & _ " printf("No");" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "//bound checking for an Integer" & @CRLF & _ "#include <stdio.h>" & @CRLF & _ "#include <stdlib.h>" & @CRLF & _ "#include <string.h>" & @CRLF & _ "" & @CRLF & _ "int main()" & @CRLF & _ "{" & @CRLF & _ " char *s1 = (char*)malloc(12*sizeof(char));" & @CRLF & _ " char *s2 = (char*)malloc(12*sizeof(char));" & @CRLF & _ " gets(s1);" & @CRLF & _ " int a = atoi(s1);" & @CRLF & _ " sprintf(s2,"%d",a);" & @CRLF & _ " if(strcmp(s1,s2)==0)" & @CRLF & _ " printf("Yes");" & @CRLF & _ " else" & @CRLF & _ " printf("No");" & @CRLF & _ "" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "//bound checking for the LCM" & @CRLF & _ "#include <stdio.h>" & @CRLF & _ "#include <stdlib.h>" & @CRLF & _ "#include <limits.h>" & @CRLF & _ "" & @CRLF & _ "unsigned long long gcd(unsigned long long a, unsigned long long b) {" & @CRLF & _ " unsigned long long temp = 0;" & @CRLF & _ " while (b != 0)" & @CRLF & _ " {" & @CRLF & _ " temp = a % b;" & @CRLF & _ " a = b;" & @CRLF & _ " b = temp;" & @CRLF & _ " }" & @CRLF & _ " return a;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "int main(void) {" & @CRLF & _ " unsigned long long a, b;" & @CRLF & _ " scanf("%llu %llu", &a, &b);" & @CRLF & _ "" & @CRLF & _ " unsigned long long UCLN = gcd(a,b);" & @CRLF & _ " if(a==0||b==0)" & @CRLF & _ " printf("N/A");" & @CRLF & _ " else if((a/UCLN) <= (ULLONG_MAX/b))" & @CRLF & _ " printf("%llu",a/UCLN*b);" & @CRLF & _ " else{" & @CRLF & _ " printf("N/A");" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " return 0;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "//dual format telephone number" & @CRLF & _ "#include<iostream>" & @CRLF & _ "#include<regex>" & @CRLF & _ "#include <string>" & @CRLF & _ "#include <stdexcept>" & @CRLF & _ "using namespace std;" & @CRLF & _ "int main()" & @CRLF & _ "{" & @CRLF & _ " regex phone10("(\\+84|0)1[0-9]{9}");" & @CRLF & _ " string st;" & @CRLF & _ " int n;" & @CRLF & _ " cin >> n;" & @CRLF & _ " getline(cin,st);" & @CRLF & _ " while(n--){" & @CRLF & _ " getline(cin, st);" & @CRLF & _ " if(regex_match(st, phone10))" & @CRLF & _ " cout << "Valid!" << endl;" & @CRLF & _ " else" & @CRLF & _ " cout << "Invalid!" << endl;" & @CRLF & _ " }" & @CRLF & _ " " & @CRLF & _ " return 0;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "//email address" & @CRLF & _ "#include <iostream>" & @CRLF & _ "#include <regex>" & @CRLF & _ "#include <string>" & @CRLF & _ "using namespace std;" & @CRLF & _ "" & @CRLF & _ "int main(){" & @CRLF & _ " regex pattern("([\\w!#$%&'*+/=?^_`{|}~-]+\\.?[\\w!#$%&'*+/=?^_`{|}~-]+)+@(\\w+(\\-\\w+)?(\\.\\w+))+");" & @CRLF & _ " int x;" & @CRLF & _ " cin >>x;" & @CRLF & _ " string line_;" & @CRLF & _ " getline(cin,line_);" & @CRLF & _ " while(x--){" & @CRLF & _ " getline(cin,line_);" & @CRLF & _ " if(regex_match(line_,pattern))" & @CRLF & _ " cout << "Valid!"<<endl;" & @CRLF & _ " else" & @CRLF & _ " cout <<"Invalid!"<<endl;" & @CRLF & _ " }" & @CRLF & _ " return 0;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "//find IP attack" & @CRLF & _ "#include <iostream>" & @CRLF & _ "#include <regex>" & @CRLF & _ "#include <string>" & @CRLF & _ "using namespace std;" & @CRLF & _ "" & @CRLF & _ "int main(){" & @CRLF & _ " regex pattern("\\d+\\ \\d+\\.\\d+(\\ ((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])){2}\\ [A-Z]+\\ \\d+ [A-Z]+\\ [\\w-+/?=&.: ]+");" & @CRLF & _ " int t;" & @CRLF & _ " string st;" & @CRLF & _ " cin >> t;" & @CRLF & _ " getline(cin, st);" & @CRLF & _ " int i = 1;" & @CRLF & _ " while(t--){" & @CRLF & _ " getline(cin, st);" & @CRLF & _ " cout << i++ << endl;" & @CRLF & _ " sregex_token_iterator pos(st.cbegin(),st.cend(), pattern, 0);" & @CRLF & _ " sregex_token_iterator end;" & @CRLF & _ " for (; pos!=end; ++pos)" & @CRLF & _ " cout << "Found " << pos->str() << endl;" & @CRLF & _ " }" & @CRLF & _ " return 0;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "//integer number" & @CRLF & _ "#include<iostream>" & @CRLF & _ "#include<regex>" & @CRLF & _ "#include <string>" & @CRLF & _ "#include <stdexcept>" & @CRLF & _ "using namespace std;" & @CRLF & _ "int main()" & @CRLF & _ "{" & @CRLF & _ " regex pattern("[\\+-]?[1-9][0-9]*");" & @CRLF & _ " string st;" & @CRLF & _ " int n;" & @CRLF & _ " cin >> n;" & @CRLF & _ " getline(cin,st);" & @CRLF & _ " while(n--){" & @CRLF & _ " getline(cin, st);" & @CRLF & _ " if(regex_match(st, pattern))" & @CRLF & _ " cout << "Valid!" << endl;" & @CRLF & _ " else" & @CRLF & _ " cout << "Invalid!" << endl;" & @CRLF & _ " }" & @CRLF & _ " " & @CRLF & _ " return 0;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "//list email in raw data" & @CRLF & _ "#include <iostream>" & @CRLF & _ "#include <regex>" & @CRLF & _ "#include <string>" & @CRLF & _ "using namespace std;" & @CRLF & _ "" & @CRLF & _ "int main(){" & @CRLF & _ " regex pattern("([\\w_-]+(\\.?[\\w_-]))+@[\\w]+([_\\w]+)?(\\.[\\w]+)+");" & @CRLF & _ " int t;" & @CRLF & _ " string st;" & @CRLF & _ " cin >> t;" & @CRLF & _ " getline(cin, st);" & @CRLF & _ " int i = 1;" & @CRLF & _ " while(t--){" & @CRLF & _ " getline(cin, st);" & @CRLF & _ " cout << i++ << endl;" & @CRLF & _ " sregex_token_iterator pos(st.cbegin(),st.cend(), pattern, 0);" & @CRLF & _ " sregex_token_iterator end;" & @CRLF & _ " for (; pos!=end; ++pos)" & @CRLF & _ " cout << "Found " << pos->str()<< endl;" & @CRLF & _ " }" & @CRLF & _ " return 0;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "//list IP in log web" & @CRLF & _ "#include <iostream>" & @CRLF & _ "#include <regex>" & @CRLF & _ "#include <string>" & @CRLF & _ "using namespace std;" & @CRLF & _ "" & @CRLF & _ "int main(){" & @CRLF & _ " regex pattern("((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])");" & @CRLF & _ " int t;" & @CRLF & _ " string st;" & @CRLF & _ " cin >> t;" & @CRLF & _ " getline(cin, st);" & @CRLF & _ " int i = 1;" & @CRLF & _ " while(t--){" & @CRLF & _ " getline(cin, st);" & @CRLF & _ " cout << i++ << endl;" & @CRLF & _ " sregex_token_iterator pos(st.cbegin(),st.cend(), pattern, 0);" & @CRLF & _ " sregex_token_iterator end;" & @CRLF & _ " for (; pos!=end; ++pos)" & @CRLF & _ " cout << "Found " << pos->str()<< endl;" & @CRLF & _ " }" & @CRLF & _ " return 0;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "//list link in a tag HTML" & @CRLF & _ "#include <iostream>" & @CRLF & _ "#include <regex>" & @CRLF & _ "#include <string>" & @CRLF & _ "using namespace std;" & @CRLF & _ "" & @CRLF & _ "int main(){" & @CRLF & _ " regex pattern("(http|https|ftp)://[\\w\\.]+([-\\w\\.]+)?(:\\d+)?([/\\w]+)?");" & @CRLF & _ " int t;" & @CRLF & _ " string st;" & @CRLF & _ " cin >> t;" & @CRLF & _ " getline(cin, st);" & @CRLF & _ " int i = 1;" & @CRLF & _ " while(t--){" & @CRLF & _ " getline(cin, st);" & @CRLF & _ " cout << i++ << endl;" & @CRLF & _ " sregex_token_iterator pos(st.cbegin(),st.cend(), pattern, 0);" & @CRLF & _ " sregex_token_iterator end;" & @CRLF & _ " for ( ; pos!=end ; ++pos )" & @CRLF & _ " cout << "Found: " << pos->str()<< endl;" & @CRLF & _ " }" & @CRLF & _ " return 0;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "//list phone number" & @CRLF & _ "#include<iostream>" & @CRLF & _ "#include<regex>" & @CRLF & _ "#include <string>" & @CRLF & _ "#include <stdexcept>" & @CRLF & _ "using namespace std;" & @CRLF & _ "int main()" & @CRLF & _ "{" & @CRLF & _ " regex pattern("((\\+84)|0)[1-9][0-9]{8,9}");" & @CRLF & _ " string st;" & @CRLF & _ " int n;" & @CRLF & _ " cin >> n;" & @CRLF & _ " getline(cin, st);" & @CRLF & _ " for(int i=1;i<=n;i++){" & @CRLF & _ " cout << i << endl;" & @CRLF & _ " getline(cin, st);" & @CRLF & _ " sregex_token_iterator pos(st.cbegin(),st.cend(), pattern, 0);" & @CRLF & _ " sregex_token_iterator end;" & @CRLF & _ " for ( ; pos!=end ; ++pos ) {" & @CRLF & _ " cout << "Found " << pos->str() << " at " << pos->first-st.begin() << endl;" & @CRLF & _ " }" & @CRLF & _ " } " & @CRLF & _ " return 0;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "//matching specific FileName" & @CRLF & _ "#include <iostream>" & @CRLF & _ "#include <regex>" & @CRLF & _ "#include <string>" & @CRLF & _ "using namespace std;" & @CRLF & _ "" & @CRLF & _ "int main(){" & @CRLF & _ " regex images("[a-zA-Z0-9\\_\\.]+\\.?[a-zA-Z0-9\\_]+\\.(([jJ][pP][gG])|([pP][nN][gG])|([gG][iI][fF]))");" & @CRLF & _ " regex docs("[a-zA-Z0-9\\_\\.]+\\.?[a-zA-Z0-9\\_]+\\.(([pP][dD][f|])|([dD][oO][cC])|([pP]{2}[tT][xX]))");" & @CRLF & _ " regex media("[a-zA-Z0-9\\_\\.]+\\.?[a-zA-Z0-9\\_]+\\.(([m|M][p|P][3|4])|([a|A][v|V][i|I]))");" & @CRLF & _ " int t;" & @CRLF & _ " string st;" & @CRLF & _ " cin >> t;" & @CRLF & _ " getline(cin, st);" & @CRLF & _ " int i = 1;" & @CRLF & _ " while(t--){" & @CRLF & _ " getline(cin, st);" & @CRLF & _ " cout << i++ << endl;" & @CRLF & _ " " & @CRLF & _ " sregex_token_iterator pos(st.cbegin(),st.cend(), images, 0);" & @CRLF & _ " sregex_token_iterator end;" & @CRLF & _ " for ( ; pos!=end ; ++pos )" & @CRLF & _ " cout << pos->str() << " : " << "hinh anh" << endl;" & @CRLF & _ " " & @CRLF & _ " sregex_token_iterator pos1(st.cbegin(),st.cend(), media, 0);" & @CRLF & _ " sregex_token_iterator end1;" & @CRLF & _ " for ( ; pos1!=end1 ; ++pos1 )" & @CRLF & _ " cout << pos1->str() << " : " << "media" << endl;" & @CRLF & _ " " & @CRLF & _ " sregex_token_iterator pos2(st.cbegin(),st.cend(), docs, 0);" & @CRLF & _ " sregex_token_iterator end2;" & @CRLF & _ " for ( ; pos2!=end2 ; ++pos2 )" & @CRLF & _ " cout << pos2->str() << " : " << "tai lieu" << endl;" & @CRLF & _ " }" & @CRLF & _ " return 0;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "//modify telephone number" & @CRLF & _ "#include <iostream>" & @CRLF & _ "#include <regex>" & @CRLF & _ "#include <string>" & @CRLF & _ "using namespace std;" & @CRLF & _ "" & @CRLF & _ "string Convert(string str){" & @CRLF & _ " string temp = "";" & @CRLF & _ " string sub = str.substr(0,4);" & @CRLF & _ " if(sub.compare("0123") ==0){" & @CRLF & _ " regex at_sign("0123");" & @CRLF & _ " string replace_by("083");" & @CRLF & _ " temp = regex_replace(str, at_sign, replace_by);" & @CRLF & _ " }else if(sub.compare("0124") ==0){" & @CRLF & _ " regex at_sign("0124");" & @CRLF & _ " string replace_by("084");" & @CRLF & _ " temp = regex_replace(str, at_sign, replace_by);" & @CRLF & _ " }else if(sub.compare("0125") ==0){" & @CRLF & _ " regex at_sign("0125");" & @CRLF & _ " string replace_by("085");" & @CRLF & _ " temp = regex_replace(str, at_sign, replace_by);" & @CRLF & _ " }" & @CRLF & _ " else if(sub.compare("0127") ==0){" & @CRLF & _ " regex at_sign("0127");" & @CRLF & _ " string replace_by("081");" & @CRLF & _ " temp = regex_replace(str, at_sign, replace_by);" & @CRLF & _ " }" & @CRLF & _ " else if(sub.compare("0129") ==0){" & @CRLF & _ " regex at_sign("0129");" & @CRLF & _ " string replace_by("082");" & @CRLF & _ " temp = regex_replace(str, at_sign, replace_by);" & @CRLF & _ " }" & @CRLF & _ " return temp;" & @CRLF & _ "}" & @CRLF & _ "int main(){" & @CRLF & _ " regex pattern("012[3-9^6]\\d{7}");" & @CRLF & _ " int t;" & @CRLF & _ " string st;" & @CRLF & _ " cin >> t;" & @CRLF & _ " getline(cin, st);" & @CRLF & _ "" & @CRLF & _ " for(int i = 1; i <= t ; i++){" & @CRLF & _ " getline(cin, st);" & @CRLF & _ " cout << i << endl;" & @CRLF & _ " sregex_token_iterator pos(st.cbegin(),st.cend(), pattern, 0);" & @CRLF & _ " sregex_token_iterator end;" & @CRLF & _ " for (; pos!=end; ++pos){" & @CRLF & _ " string str1 = pos->str();" & @CRLF & _ " cout << "Thay doi: " << Convert(str1) << endl;" & @CRLF & _ " }" & @CRLF & _ " }" & @CRLF & _ " return 0;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "//numeric string leading without zero" & @CRLF & _ "#include<iostream>" & @CRLF & _ "#include<regex>" & @CRLF & _ "#include <string>" & @CRLF & _ "#include <stdexcept>" & @CRLF & _ "using namespace std;" & @CRLF & _ "int main()" & @CRLF & _ "{" & @CRLF & _ " regex pattern("[1-9][0-9]*");" & @CRLF & _ " string st;" & @CRLF & _ " int n;" & @CRLF & _ " cin >> n;" & @CRLF & _ " getline(cin,st);" & @CRLF & _ " while(n--){" & @CRLF & _ " getline(cin, st);" & @CRLF & _ " if(regex_match(st, pattern))" & @CRLF & _ " cout << "Valid!" << endl;" & @CRLF & _ " else" & @CRLF & _ " cout << "Invalid!" << endl;" & @CRLF & _ " }" & @CRLF & _ " " & @CRLF & _ " return 0;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "//numeric string" & @CRLF & _ "#include<iostream>" & @CRLF & _ "#include<regex>" & @CRLF & _ "#include <string>" & @CRLF & _ "#include <stdexcept>" & @CRLF & _ "using namespace std;" & @CRLF & _ "int main()" & @CRLF & _ "{" & @CRLF & _ " regex pattern("[0-9]*");" & @CRLF & _ " string st;" & @CRLF & _ " int n;" & @CRLF & _ " cin >> n;" & @CRLF & _ " getline(cin,st);" & @CRLF & _ " while(n--){" & @CRLF & _ " getline(cin, st);" & @CRLF & _ " if(regex_match(st, pattern))" & @CRLF & _ " cout << "Valid!" << endl;" & @CRLF & _ " else" & @CRLF & _ " cout << "Invalid!" << endl;" & @CRLF & _ " }" & @CRLF & _ " " & @CRLF & _ " return 0;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "//telephone number international format" & @CRLF & _ "#include<iostream>" & @CRLF & _ "#include<regex>" & @CRLF & _ "#include <string>" & @CRLF & _ "#include <stdexcept>" & @CRLF & _ "using namespace std;" & @CRLF & _ "int main()" & @CRLF & _ "{" & @CRLF & _ " regex phone10("\\+841(\\.[0-9]{3}){3}");" & @CRLF & _ " string st;" & @CRLF & _ " int n;" & @CRLF & _ " cin >> n;" & @CRLF & _ " getline(cin,st);" & @CRLF & _ " while(n--){" & @CRLF & _ " getline(cin, st);" & @CRLF & _ " if(regex_match(st, phone10))" & @CRLF & _ " cout << "Valid!" << endl;" & @CRLF & _ " else" & @CRLF & _ " cout << "Invalid!" << endl;" & @CRLF & _ " }" & @CRLF & _ " " & @CRLF & _ " return 0;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYGLOBALFULLMATCH) Local $aFullArray[0] For $i = 0 To UBound($aArray) -1 _ArrayConcatenate($aFullArray, $aArray[$i]) Next $aArray = $aFullArray ; Present the entire match result _ArrayDisplay($aArray, "Result")

Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm