Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

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

Substitution

Processing...

Code Generator

Generated Code

#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox Local $sRegex = "(?m)^\d+." Local $sString = "1. // #include <conio.h>" & @CRLF & _ "2. // #include <stdio.h>" & @CRLF & _ "3. #include <iostream>" & @CRLF & _ "4. // #include <ctype.h>" & @CRLF & _ "5. #include <cstring>" & @CRLF & _ "6. using namespace std;" & @CRLF & _ "7. class CON_VAT" & @CRLF & _ "8. {" & @CRLF & _ "9. protected:" & @CRLF & _ "10. char *ten;" & @CRLF & _ "11. public:" & @CRLF & _ "12. CON_VAT()" & @CRLF & _ "13. {ten = NULL;" & @CRLF & _ "14. }" & @CRLF & _ "15. CON_VAT(char *ten1)" & @CRLF & _ "16. {" & @CRLF & _ "17. strcpy(ten,ten1);" & @CRLF & _ "18. }" & @CRLF & _ "19. virtual void xung_ten()" & @CRLF & _ "20. { }" & @CRLF & _ "21. } ;" & @CRLF & _ "22. class CON_MEO:public CON_VAT" & @CRLF & _ "23. {" & @CRLF & _ "24. public:" & @CRLF & _ "25. CON_MEO() : CON_VAT()" & @CRLF & _ "26. { }" & @CRLF & _ "27. CON_MEO(char *ten1) : CON_VAT(ten1)" & @CRLF & _ "28. { }" & @CRLF & _ "29. virtual void xung_ten()" & @CRLF & _ "30. {" & @CRLF & _ "31. cout << "\nToi la chu meo: " << ten ;" & @CRLF & _ "32. }" & @CRLF & _ "33. };" & @CRLF & _ "34. class CON_CHO:public CON_VAT" & @CRLF & _ "35. {" & @CRLF & _ "36. public:" & @CRLF & _ "37. CON_CHO() : CON_VAT()" & @CRLF & _ "38. { }" & @CRLF & _ "39. CON_CHO(char *ten1) : CON_VAT(ten1)" & @CRLF & _ "40. { }" & @CRLF & _ "41. virtual void xung_ten()" & @CRLF & _ "42. {" & @CRLF & _ "43. cout << "\nToi la chu cho: " << ten ;" & @CRLF & _ "44. }" & @CRLF & _ "45. };" & @CRLF & _ "46. class DS_CON_VAT // Danh sach con vat" & @CRLF & _ "47. {" & @CRLF & _ "48. private:" & @CRLF & _ "49. int max_so_con_vat;" & @CRLF & _ "50. int so_con_vat;" & @CRLF & _ "51. CON_VAT **h ;" & @CRLF & _ "52. public:" & @CRLF & _ "53. DS_CON_VAT(int max);" & @CRLF & _ "54. ~DS_CON_VAT();" & @CRLF & _ "55. int nhap(CON_VAT *c);" & @CRLF & _ "56. CON_VAT* xuat(int n);" & @CRLF & _ "57. void thong_ke();" & @CRLF & _ "58. } ;" & @CRLF & _ "59. DS_CON_VAT::DS_CON_VAT(int max)" & @CRLF & _ "60. {" & @CRLF & _ "61. max_so_con_vat = max;" & @CRLF & _ "62. so_con_vat = 0;" & @CRLF & _ "63. h = new CON_VAT*[max];" & @CRLF & _ "64. for (int i=0; i<max; ++i)" & @CRLF & _ "65. h[i] = NULL;" & @CRLF & _ "66. }" & @CRLF & _ "67. DS_CON_VAT::~DS_CON_VAT()" & @CRLF & _ "68. {" & @CRLF & _ "69. max_so_con_vat = 0;" & @CRLF & _ "70. so_con_vat = 0;" & @CRLF & _ "71. delete h;" & @CRLF & _ "72. }" & @CRLF & _ "73. int DS_CON_VAT::nhap(CON_VAT *c)" & @CRLF & _ "74. {" & @CRLF & _ "75. if (so_con_vat==max_so_con_vat)" & @CRLF & _ "76. return 0;" & @CRLF & _ "77. int i=0;" & @CRLF & _ "78. while (h[i]!=NULL) ++i;" & @CRLF & _ "79. h[i]=c;" & @CRLF & _ "80. so_con_vat++ ;" & @CRLF & _ "81. return (i+1);" & @CRLF & _ "82. }" & @CRLF & _ "83. CON_VAT* DS_CON_VAT::xuat(int n)" & @CRLF & _ "84. {" & @CRLF & _ "" & @CRLF & _ "85. if (n<1 || n > max_so_con_vat)" & @CRLF & _ "86. return NULL ;" & @CRLF & _ "87. --n ;" & @CRLF & _ "88. if (h[n])" & @CRLF & _ "89. {" & @CRLF & _ "90. CON_VAT *c = h[n];" & @CRLF & _ "91. h[n]=NULL;/*----------------------???---------------------*/" & @CRLF & _ "92. so_con_vat-- ;" & @CRLF & _ "93. return c;" & @CRLF & _ "94. }" & @CRLF & _ "95. else" & @CRLF & _ "96. return NULL;" & @CRLF & _ "97. }" & @CRLF & _ "98. void DS_CON_VAT::thong_ke()" & @CRLF & _ "99. {" & @CRLF & _ "100. if (so_con_vat)" & @CRLF & _ "101. {" & @CRLF & _ "102. cout << "\n" ;" & @CRLF & _ "103. for (int i=0; i<max_so_con_vat; ++i)" & @CRLF & _ "104. if (h[i])" & @CRLF & _ "105. h[i]->xung_ten();" & @CRLF & _ "106. }" & @CRLF & _ "107. }" & @CRLF & _ "108. CON_CHO c1("MUC");" & @CRLF & _ "109. CON_CHO c2("VEN");" & @CRLF & _ "110. CON_CHO c3("LAI");" & @CRLF & _ "111. CON_CHO c4("NHAT");" & @CRLF & _ "112. CON_CHO c5("BONG");" & @CRLF & _ "113. CON_MEO m1("MUOP");" & @CRLF & _ "114. CON_MEO m2("DEN");" & @CRLF & _ "115. CON_MEO m3("TRANG");" & @CRLF & _ "116. CON_MEO m4("TAM THE");" & @CRLF & _ "117. CON_MEO m5("VANG");" & @CRLF & _ "118. DS_CON_VAT d(20);" & @CRLF & _ "119. int main()" & @CRLF & _ "120. {" & @CRLF & _ "" & @CRLF & _ "121. //clrscr();" & @CRLF & _ "122. d.nhap(&c1);" & @CRLF & _ "123. int im2 = d.nhap(&m2);" & @CRLF & _ "124. d.nhap(&c3);" & @CRLF & _ "125. d.nhap(&m1);" & @CRLF & _ "126. int ic4 = d.nhap(&c4);" & @CRLF & _ "127. d.nhap(&c5);" & @CRLF & _ "128. d.nhap(&m5);" & @CRLF & _ "129. d.nhap(&c2);" & @CRLF & _ "130. d.nhap(&m3);" & @CRLF & _ "131. d.thong_ke();" & @CRLF & _ "132. d.xuat(im2);" & @CRLF & _ "133. d.xuat(ic4);" & @CRLF & _ "134. d.thong_ke();" & @CRLF & _ "135. //getch();" & @CRLF & _ "136. }" Local $sSubst = "" Local $sResult = StringRegExpReplace($sString, $sRegex, $sSubst) MsgBox($MB_SYSTEMMODAL, "Result", $sResult)

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