Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
Sponsors
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
Processing...

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)kthpppp" Local $sString = "//" & @CRLF & _ "///*" & @CRLF & _ "//" & @CRLF & _ "//// Bai 2" & @CRLF & _ "//#include <iostream>" & @CRLF & _ "//" & @CRLF & _ "//using namespace std;" & @CRLF & _ "//" & @CRLF & _ "//int a, b;" & @CRLF & _ "//long long c;" & @CRLF & _ "//" & @CRLF & _ "//void init() {" & @CRLF & _ "// cout << "Khoi tao: " << endl;" & @CRLF & _ "// do {" & @CRLF & _ "// cout << " - Nhap vao gia tri cua a: ";" & @CRLF & _ "// cin >> a;" & @CRLF & _ "// } while (10 > a || a > 50);" & @CRLF & _ "// " & @CRLF & _ "// do {" & @CRLF & _ "// cout << " - Nhap vao gia tri cua b: ";" & @CRLF & _ "// cin >> b;" & @CRLF & _ "// } while (10 > b || b > 50 || a>=b);" & @CRLF & _ "//" & @CRLF & _ "// c = a*b;" & @CRLF & _ "//}" & @CRLF & _ "//" & @CRLF & _ "//void timUoc(int a) {" & @CRLF & _ "// int i;" & @CRLF & _ "// for (i = 1; i < a ; i++) {" & @CRLF & _ "// if (a%i == 0) {" & @CRLF & _ "// cout << " " << i;" & @CRLF & _ "// }" & @CRLF & _ "// }" & @CRLF & _ "// cout << endl;" & @CRLF & _ "//}" & @CRLF & _ "//" & @CRLF & _ "//int checkPP(int a) {" & @CRLF & _ "// int i;" & @CRLF & _ "// long sum;" & @CRLF & _ "// sum = 1;" & @CRLF & _ "//" & @CRLF & _ "// for (i = 2; i < a ; i++) {" & @CRLF & _ "// if (a%i == 0) {" & @CRLF & _ "// sum += i;" & @CRLF & _ "// }" & @CRLF & _ "// }" & @CRLF & _ "//" & @CRLF & _ "// if (sum > a)" & @CRLF & _ "// return 1;" & @CRLF & _ "// return 0;" & @CRLF & _ "//}" & @CRLF & _ "//" & @CRLF & _ "//" & @CRLF & _ "//int main() {" & @CRLF & _ "//" & @CRLF & _ "// init();" & @CRLF & _ "//" & @CRLF & _ "// // Cau 1" & @CRLF & _ "// cout << endl << "Cau 1: " << endl;" & @CRLF & _ "// timUoc(c);" & @CRLF & _ "//" & @CRLF & _ "// // Cau 2" & @CRLF & _ "// cout << endl << "Cau 2: " << endl;" & @CRLF & _ "// cout << " - C = " << c << endl;" & @CRLF & _ "// if (checkPP(c))" & @CRLF & _ "// cout << " - " << c << " la so phong phu" << endl;" & @CRLF & _ "// else" & @CRLF & _ "// cout << " - " << c << " khong la so phong phu" << endl;" & @CRLF & _ "//" & @CRLF & _ "// // Cau 3" & @CRLF & _ "// cout << endl << "Cau 3: " << endl;" & @CRLF & _ "// for (int i = a; i <= b; i++) {" & @CRLF & _ "// if (checkPP(i))" & @CRLF & _ "// cout << " " << i;" & @CRLF & _ "// }" & @CRLF & _ "//" & @CRLF & _ "// cout << endl << endl;" & @CRLF & _ "//" & @CRLF & _ "// system("pause");" & @CRLF & _ "//}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "//" & @CRLF & _ "//// Bai 3" & @CRLF & _ "//#include <iostream>" & @CRLF & _ "//#include <string>" & @CRLF & _ "//" & @CRLF & _ "//using namespace std;" & @CRLF & _ "//" & @CRLF & _ "//string s;" & @CRLF & _ "//char KQ[65];" & @CRLF & _ "//int n;" & @CRLF & _ "//" & @CRLF & _ "//" & @CRLF & _ "//int check_Char(string s) {" & @CRLF & _ "// int i, len;" & @CRLF & _ "// len = s.length();" & @CRLF & _ "// for (i = 0; i < len; i++) {" & @CRLF & _ "// if (s[i] - 48 < 0 || s[i] - 48 > 9)" & @CRLF & _ "// return 0;" & @CRLF & _ "// }" & @CRLF & _ "//" & @CRLF & _ "// return 1;" & @CRLF & _ "//}" & @CRLF & _ "//" & @CRLF & _ "//void init() {" & @CRLF & _ "// int len;" & @CRLF & _ "// cout << "Khoi tao: " << endl;" & @CRLF & _ "// " & @CRLF & _ "// do {" & @CRLF & _ "// cout << " - Nhap vao chuoi S: ";" & @CRLF & _ "// getline(cin, s);" & @CRLF & _ "// len = s.length();" & @CRLF & _ "// } while (1 > len || len > 20 || !check_Char(s));" & @CRLF & _ "//" & @CRLF & _ "//}" & @CRLF & _ "//" & @CRLF & _ "//unsigned long long convertToLong(string s) {" & @CRLF & _ "// unsigned long long number = 0;" & @CRLF & _ "// int i, len;" & @CRLF & _ "//" & @CRLF & _ "// len = s.length();" & @CRLF & _ "//" & @CRLF & _ "// for (i = 0; i < len; i++) {" & @CRLF & _ "// number = number * 10 + s[i] - 48;" & @CRLF & _ "// }" & @CRLF & _ "//" & @CRLF & _ "// return number;" & @CRLF & _ "//}" & @CRLF & _ "//" & @CRLF & _ "//void convertToBinary(unsigned long long a) {" & @CRLF & _ "// int i;" & @CRLF & _ "// i = 0;" & @CRLF & _ "// while (a) {" & @CRLF & _ "// KQ[i] = a % 2 + 48;" & @CRLF & _ "// a = a / 2;" & @CRLF & _ "// i++;" & @CRLF & _ "// }" & @CRLF & _ "//" & @CRLF & _ "// n = i;" & @CRLF & _ "//}" & @CRLF & _ "//" & @CRLF & _ "//void valueMax() {" & @CRLF & _ "// int i, flag, j;" & @CRLF & _ "// char* output = (char*)calloc(n, sizeof(char));" & @CRLF & _ "//" & @CRLF & _ "// flag = 0;" & @CRLF & _ "// j = 0;" & @CRLF & _ "// for (i = n - 1; i >= 0; i--) {" & @CRLF & _ "// if (KQ[i] != '0') {" & @CRLF & _ "// output[j] = KQ[i];" & @CRLF & _ "// j++;" & @CRLF & _ "// }" & @CRLF & _ "// else {" & @CRLF & _ "// if (flag == 0 && KQ[i] == '0')" & @CRLF & _ "// flag = 1;" & @CRLF & _ "// else {" & @CRLF & _ "// output[j] = KQ[i];" & @CRLF & _ "// j++;" & @CRLF & _ "// }" & @CRLF & _ "// }" & @CRLF & _ "// }" & @CRLF & _ "//" & @CRLF & _ "// // In KQ" & @CRLF & _ "// for (i = 0; i < j; i++)" & @CRLF & _ "// cout << output[i];" & @CRLF & _ "//" & @CRLF & _ "//" & @CRLF & _ "//}" & @CRLF & _ "//" & @CRLF & _ "//int main() {" & @CRLF & _ "// int i;" & @CRLF & _ "// unsigned long long value;" & @CRLF & _ "// char* binary = (char*)calloc(n, sizeof(char));" & @CRLF & _ "//" & @CRLF & _ "// // Cau 1" & @CRLF & _ "// cout << endl << "Cau 1: " << endl;" & @CRLF & _ "// init();" & @CRLF & _ "//" & @CRLF & _ "// // Cau 2" & @CRLF & _ "// cout << endl << "Cau 2: " << endl;" & @CRLF & _ "// cout << " " << s << " = ";" & @CRLF & _ "// value = convertToLong(s);" & @CRLF & _ "// convertToBinary(value);" & @CRLF & _ "// for (i = n - 1; i >= 0; i--)" & @CRLF & _ "// cout << KQ[i];" & @CRLF & _ "//" & @CRLF & _ "// // Cau 3" & @CRLF & _ "// cout << endl << "Cau 3: " << endl;" & @CRLF & _ "// cout << " - Gia tri cua S: " << s << endl;" & @CRLF & _ "// cout << " - Gia tri cua Sb la: ";" & @CRLF & _ "// for (i = n - 1; i >= 0; i--)" & @CRLF & _ "// cout << KQ[i];" & @CRLF & _ "//" & @CRLF & _ "// cout << endl << " - Gia tri cua Sb' la: ";" & @CRLF & _ "// valueMax();" & @CRLF & _ "//" & @CRLF & _ "// cout << endl << endl;" & @CRLF & _ "//" & @CRLF & _ "// system("pause");" & @CRLF & _ "//}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "// Bai 1" & @CRLF & _ "#include <iostream>" & @CRLF & _ "" & @CRLF & _ "using namespace std;" & @CRLF & _ "" & @CRLF & _ "int a, b;" & @CRLF & _ "" & @CRLF & _ "void init() {" & @CRLF & _ " cout << "Khoi tao: " << endl;" & @CRLF & _ " cout << " - Nhap gia tri cua a: ";" & @CRLF & _ " cin >> a;" & @CRLF & _ " cout << " - Nhap gia tri cua b: ";" & @CRLF & _ " cin >> b;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "double TBC() {" & @CRLF & _ " double KQ;" & @CRLF & _ " KQ = (a + b)*1.0 / 2;" & @CRLF & _ "" & @CRLF & _ " return KQ;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "int abs(int a) {" & @CRLF & _ " if (a > 0)" & @CRLF & _ " return a;" & @CRLF & _ " return 0 - a;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "int main() {" & @CRLF & _ " init();" & @CRLF & _ " double KQ;" & @CRLF & _ "" & @CRLF & _ " // Cau 1" & @CRLF & _ " KQ = TBC();" & @CRLF & _ " cout << endl << "Cau 1: " << endl;" & @CRLF & _ " cout << " - Trung binh cong cua " << a << " & " << b << " la: " <<KQ;" & @CRLF & _ "" & @CRLF & _ " // Cau 2" & @CRLF & _ " cout << endl << "Cau 2: " << endl;" & @CRLF & _ " if (abs(a) > abs(b))" & @CRLF & _ " cout << "a^2 > b^2" << endl;" & @CRLF & _ " else if (abs(a) < abs(b))" & @CRLF & _ " cout << "a^2 < b^2" << endl;" & @CRLF & _ " else" & @CRLF & _ " cout << "a^2 = b^2" << endl;" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ " system("pause");" & @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