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

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)^\d*\n(.*)\n([^\d].*|)" Local $sString = "1" & @CRLF & _ "Mecca (مكة)" & @CRLF & _ "Trading hub and sanctuary in pre-Islamic Arabia; holy city to Muslims; current capital of Makkah Province, Saudi Arabia" & @CRLF & _ "2" & @CRLF & _ "Medina (المدينة)" & @CRLF & _ "Political seat of Muhammad, and first capital of the Rashidun Caliphate; current capital of Al Madinah Province, Saudi Arabia" & @CRLF & _ "3" & @CRLF & _ "Damascus (دمشق)" & @CRLF & _ "Capital of the Umayyad dynasty; current capital of Syria" & @CRLF & _ "4" & @CRLF & _ "Baghdad (بغداد)" & @CRLF & _ "Second capital of the Abbasid dynasty, and actual seat of Harun al-Rashid; current capital of Iraq" & @CRLF & _ "5" & @CRLF & _ "Najran (نجران)" & @CRLF & _ "Christian center in 5th-7th century Arabia; current capital of Najran Province, Saudi Arabia " & @CRLF & _ "6" & @CRLF & _ "Kufah (الكوفة)" & @CRLF & _ "Second capital of the Rashidun Caliphate under Ali's rule; first capital of the Abbasid dynasty; city in modern-day Iraq" & @CRLF & _ "7" & @CRLF & _ "Basra (البصرة)" & @CRLF & _ "City in Iraq" & @CRLF & _ "8" & @CRLF & _ "Khurasan (خراسان)" & @CRLF & _ "Region corresponding to modern Afghanistan and northeast Iran" & @CRLF & _ "9" & @CRLF & _ "Anjar (عنجر)" & @CRLF & _ "City in Lebanon" & @CRLF & _ "10" & @CRLF & _ "Fustat (الفسطاط)" & @CRLF & _ "Old city of Cairo" & @CRLF & _ "11" & @CRLF & _ "Aden (عدن)" & @CRLF & _ "City in Yemen" & @CRLF & _ "12" & @CRLF & _ "Yamama (اليمامة)" & @CRLF & _ "Modern Najd region of Saudi Arabia" & @CRLF & _ "13" & @CRLF & _ "Muscat (مسقط)" & @CRLF & _ "Capital of Oman" & @CRLF & _ "14" & @CRLF & _ "Mansura (المنصورة)" & @CRLF & _ "City in Egypt" & @CRLF & _ "15" & @CRLF & _ "Bukhara (بخارى)" & @CRLF & _ "Modern day Buxoro, capital of Buxoro Province, Uzbekistan" & @CRLF & _ "16" & @CRLF & _ "Fez (فاس)" & @CRLF & _ "Shared with Morocco, not buildable if they are in the game" & @CRLF & _ "17" & @CRLF & _ "Shiraz (شيراز)" & @CRLF & _ "Capital of Fārs Province, Iran" & @CRLF & _ "18" & @CRLF & _ "Merw (ميرف)" & @CRLF & _ "Modern day Mary; capital of Mary Province, Turkmenistan" & @CRLF & _ "19" & @CRLF & _ "Balkh (بلخ)" & @CRLF & _ "City in Afghanistan" & @CRLF & _ "20" & @CRLF & _ "Mosul (الموصل)" & @CRLF & _ "City in Iraq" & @CRLF & _ "21" & @CRLF & _ "Aydab (؟؟؟؟؟)" & @CRLF & _ "22" & @CRLF & _ "Bayt Ras (؟؟؟؟؟؟)" & @CRLF & _ "23" & @CRLF & _ "Suhar (صحار)" & @CRLF & _ "City in Oman" & @CRLF & _ "24" & @CRLF & _ "Taif (طائف)" & @CRLF & _ "City in Saudi Arabia" & @CRLF & _ "25" & @CRLF & _ "Hama (حماة)" & @CRLF & _ "Capital of Hamāh Governorate, Syria" & @CRLF & _ "26" & @CRLF & _ "Tabuk (تبوك)" & @CRLF & _ "Capital of Tabūk Province, Saudi Arabia" & @CRLF & _ "27" & @CRLF & _ "Sana'a (صنعاء)" & @CRLF & _ "Capital of Yemen" & @CRLF & _ "28" & @CRLF & _ "Shihr (الشحر)" & @CRLF & _ "City in Yemen" & @CRLF & _ "29" & @CRLF & _ "Tripoli (طرابلس)" & @CRLF & _ "Capital of Libya" & @CRLF & _ "30" & @CRLF & _ "Tunis (تونس)" & @CRLF & _ "Capital of Tunisia" & @CRLF & _ "31" & @CRLF & _ "Kairouan (القيروان)" & @CRLF & _ "City in Tunisia" & @CRLF & _ "32" & @CRLF & _ "Algiers (الجزائر)" & @CRLF & _ "Capital of Algeria" & @CRLF & _ "33" & @CRLF & _ "Oran (وهران)" & @CRLF & _ "City in Algeria" & @CRLF & _ "34" & @CRLF & _ "Tangier (طنجة)" & @CRLF & _ "Shared with Morocco, not buildable if they are in the game" & @CRLF & _ "35" & @CRLF & _ "Casablanca (الدار البيضاء)" & @CRLF & _ "Shared with Morocco, not buildable if they are in the game" & @CRLF & _ "36" & @CRLF & _ "Marrakech (مراكش)" & @CRLF & _ "Shared with Morocco, not buildable if they are in the game" 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