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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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)\(+[A-Za-z,_]+\)" Local $sString = "(((((((((((((((((((((((((((Cb_agil,M_leuco),(C_chrys,C_torqu)),M_sphin),Papi_Pa),Cer_lho),(P_hamad,(L_albig,(Tupa_ge,(P_anubi,L_aterr))))),M_sylva),Maca_ma),(M_thibe,(M_arcto,(M_siber,((((M_fusca,M_cyclo),M_fasci),M_mulat),(M_silen,(M_nemes,(M_orchr,(M_tonke,Maca_ni))))))))),((((C_aethi,C_sabae),(C_cynos,Erythro)),A_nigro),((((((Tupa_ob,Tupa_ph),Tupa_ha),(Tupa_de,Tupa_fr)),Tupa_ve),Tupa_au),(M_ogoue,((((C_negle,C_hamly),C_albog),C_diana),((C_wolfi,Cercop_),(C_petau,(Cercopi,(C_ascan,Cerc_ce))))))))),(Cb_ango,PilioCb)),(Cb_guer,(Presb_c,(P_melal,((((Semno_h,S_entel),S_entll),Nasalis),(P_nigri,(P_ciner,(P_nemae,Rhinopi)))))))),(Noma_ga,(((Noma_le,Noma_si),Noma_co),(((hylo_ag,hyloba_),hylo_mu),(Symphal,(png_pyg,(png_abe,((Homo_sa,Gorilla),(Pan_pan,(Ptroglo,P_trogl)))))))))),Galeopt),Tupa_ba),Cb_poly),((((((((A_hybri,A_fusci),A_geoff),(B_hypox,Lagot_c)),A_belze),(Atel_ch,B_arach)),A_panis),(L_lagot,Alutbel)),(Tupa_sy,(((((((C_melan,C_satan),P_irror),Cacaj_c),C_israe),C_coimb),(C_perso,C_nigri)),(Pitheci,(((((C_brunn,C_cupre),C_calig),C_donac),Callic_),(((Alouat_,Alout_S),A_palli),(S_boliv,(Saim_us,(S_sciur,(S_oerst,((((S_geoff,S_imper),S_labia),S_oedip),(S_mysta,(((S_marti,S_midas),S_fusci),(S_bicol,((Mico_hu,C_goeld),(((((Ca_geof,Ca_kuhl),Ca_peni),(Ca_jacc,Cebuell)),Ca_auri),(Mico_ar,(L_chrys,(L_rosal,((A_Linus,A_trivi),(C_xanth,(Cebs_ap,(C_robus,((C_capuc,C_oliva),(C_albif,(AaBoliv,(A_nancy,(AaInful,Aot_aza))))))))))))))))))))))))))))),Tupa_gl),Cynocep),Tupa_mi),rabbitr),(ArctoC_,(N_pygma,L_tardi))),Perodic),((((N_benga,N_couca),G_seneg),Daubent),(P_ver_c,((P_verre,P_tatte),(P_edwar,((P_diade,Avahi_l),(((E_rubri,Vv_rubr),E_coron),(((((((((Eul_mac,EuMac_f),Eulem_r),E_colla),E_sanfo),(Eul_ful,E_albif)),Eul_Mon),H_grise),Vv_vari),((H_occid,L_catta),(Lepi_ja,(L_ankar,(L_rufic,((L_septe,L_dorsa),(Micbus2,(Micbus1,(Mirza_z,Chei_me)))))))))))))))),O_crass),G_Galag),O_garne,G_thoma);" & @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