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 the latest version of the regex crate in your Cargo.toml extern crate regex; use regex::Regex; fn main() { let regex = Regex::new(r"(?m)\(+[A-Za-z,_0-9]+\)\d+").unwrap(); let string = "((TGL_4_Tupaia_glis,CNE_1_Cercopithecus_neglectus)5,TMI_1_Tupaia_minor,(((CVA_5_Galeopterus_variegatus,CVO_1_Cynocephalus_volans)79,(rabbit_rabbit_rabbit,SAU_1_Saimiri_ustus)0)1,((((GSE_1_Galago_senegalensis,(GGR_2_Otolemur_garnetti,OCR_1_Otolemur_crassicaudatus)73)91,((LTA_2_Loris_tardigradus,(NPY_1_Nycticebus_pygmaeus,(NBE_1_Nycticebus_bengalensis,NCO_2_Nycticebus_coucang)92)94)73,(ACL_1_Arctocebus_calabarensis,PEP_2_Perodicticus_potto)77)25)80,(DMD_5_Daubentonia_madagascarie,((ALN_1_Avahi_laniger,((PTA_1_Propithecus_tattersalli,(PVE_1_Propithecus_verreauxi,PVC_2_Propithecus_verreauxi_co)50)61,(PDI_2_Propithecus_diadema,PED_1_Propithecus_edwardsi)18)96)95,((CMD_1_Cheirogaleus_medius,(CMI_3_Microcebus_murinus_subsp,MCE_1_Mirza_zaza)98)99,((LJA_1_Lepilemur_jamesi,(LER_1_Lepilemur_ruficaudatus,(LAN_1_Lepilemur_ankaranensis,(LDO_1_Lepilemur_dorsalis,LSP_1_Lepilemur_septentrionali)21)72)59)97,((LCT_10_Lemur_catta,(HOC_1_Hapalemur_occidentalis,HGR_1_Hapalemur_griseus)81)47,((VVA_2_Varecia_variegata_varieg,VVA_7_Varecia_variegata_rubra)85,(EFL_15_Eulemur_collaris,(ERF_1_Eulemur_rufus,((EFL_7_Eulemur_albifrons,EMC_1_Eulemur_macaco)7,(ECR_2_Eulemur_coronatus,EMO_1_Eulemur_mongoz)7)4)15)73)37)29)38)30)40)30)27,((TBA_1_Tarsius_bancanus,TSY_1_Tarsius_syrichta)58,(((GMO_4_Galago_moholi,((BAR_1_Brachyteles_arachnoides,(CBS_1_Callicebus_brunneus,BHY_1_Brachyteles_hypoxanthus)1)1,(((ACA_3_Alouatta_caraya,ASA_1_Alouatta_sara)77,(EMC_5_Eulemur_macaco_flavifron,(ABE_1_Alouatta_belzebul,APL_1_Alouatta_palliata)79)0)0,(MMR_2_Microcebus_murinus_subsp,((EFL_16_Eulemur_sanfordi,(LAC_2_Lagothrix_cana,LLG_1_Lagothrix_lagotricha)82)0,(ERB_4_Eulemur_rubriventer,(APC_1_Ateles_paniscus,(ACM_1_Ateles_chamek,(AFC_7_Ateles_fusciceps,(AHY_1_Ateles_hybridus,(ABZ_1_Ateles_belzebuth,AGO_2_Ateles_geoffroyi)7)4)3)17)86)0)0)0)0)0)0,((((CAP_13_Cebus_apella,((CEA_1_Cebus_albifrons,(COV_1_Cebus_olivaceus,CCP_3_Cebus_capucinus)42)67,(CRO_1_Cebus_robustus,CXA_1_Cebus_xanthosternos)12)16)96,((LCH_1_Leontopithecus_chrysomel,LRO_244_Leontopithecus_rosalia)88,(SMD_1_Saguinus_midas,(((SLA_1_Saguinus_labiatus,(SMY_3_Saguinus_mystax,(SGE_3_Saguinus_geoffroyi,SOE_3_Saguinus_oedipus)14)9)40,(SIM_2_Saguinus_imperator,SFU_6_Saguinus_fuscicollis)17)38,(SBI_1_Saguinus_bicolor,(SSI_1_Saguinus_martinsi,(CGO_1_Callimico_goeldii,((CAI_1_Callithrix_aurita,CPY_5_Cebuella_pygmaea)26,((CKU_1_Callithrix_kuhlii,(CJA_1_Callithrix_jacchus,(CPE_10_Callithrix_penicillata,CGE_4_Callithrix_geoffroyi)20)11)66,(MHU_1_Mico_humeralifer,CAR_1_Mico_argentata)49)37)37)13)1)1)1)32)74)16,((ATR_1_Aotus_trivirgatus,(ALM_1_Aotus_lemurinus_griseime,(ANA_1_Aotus_nancymaae,(AZA_1_Aotus_azarae,(AZB_1_Aotus_azarae_boliviensis,AZI_1_Aotus_azarae_infulatus)89)19)51)44)92,(SBO_3_Saimiri_boliviensis_boli,(SOO_1_Saimiri_oerstedii_oerste,SSC_7_Saimiri_sciureus)90)85)15)66,((((CCG_1_Callicebus_caligatus,CDO_1_Callicebus_donacophilus)65,(CMH_1_Callicebus_moloch,CCU_2_Callicebus_cupreus)27)48,(CNI_1_Callicebus_nigrifrons,(CCO_1_Callicebus_coimbrai,CLP_1_Callicebus_personatus)65)54)90,((CIS_1_Chiropotes_israelita,CSA_2_Chiropotes_satanas_chiro)68,(((PIR_1_Pithecia_irrorata,PPT_1_Pithecia_pithecia)98,(CAM_1_Cacajao_melanocephalus,CCL_1_Cacajao_calvus)88)66,(EFL_4_Eulemur_fulvus,GTH_1_Galago_thomasi)1)0)1)0)0)1,(((HLA_1_Hylobates_lar,(SSY_2_Symphalangus_syndactylus,(HAG_6_Hylobates_agilis,(HMU_6_Hylobates_muelleri,(NGA_2_Nomascus_gabriellae,(NCN_2_Nomascus_concolor,(HCO_3_Nomascus_leucogenys,NSI_1_Nomascus_siki)12)10)65)19)24)36)88,((HSA_34_Homo_sapiens,(GGO_9_Gorilla_gorilla,(PTR_60_Pan_troglodytes_troglod,(PTR_104_Pan_troglodytes_verus,PPN_8_Pan_paniscus)19)35)65)90,(PPY_155_Pongo_abelii,PPY_157_Pongo_pygmaeus)91)63)62,(((TGE_2_Theropithecus_gelada,(PPP_2_Papio_papio,(PHM_1_Papio_hamadryas,(NLA_2_Nasalis_larvatus,(MSP_12_Mandrillus_sphinx,(MLE_2_Mandrillus_leucophaeus,(CTR_1_Cercocebus_torquatus,(CAC_1_Cercocebus_agilis,CCY_1_Cercocebus_chrysogaster)62)25)10)14)67)4)1)2,((LAA_1_Lophocebus_albigena,LAT_2_Lophocebus_aterrimus)92,(MCA_1_Macaca_maura,((MSE_1_Macaca_siberu,((RBR_1_Rhinopithecus_brelichi,((PNI_1_Pygathrix_nigripes,(PCN_2_Pygathrix_cinerea,PNE_2_Pygathrix_nemaeus)53)60,((PCM_1_Presbytis_comata,PME_2_Presbytis_melalophos)66,(((TAU_1_Trachypithecus_auratus,(TOB_4_Trachypithecus_obscurus,(THA_1_Trachypithecus_hatinhens,(TDE_1_Trachypithecus_delacouri,TFR_1_Trachypithecus_francoisi)7)11)23)61,(TPH_1_Trachypithecus_phayrei,(TVV_2_Trachypithecus_vetulus_m,(SEE_1_Semnopithecus_entellus_e,(SHE_1_Semnopithecus_hector,SEF_2_Semnopithecus_entellus)67)72)60)16)53,(PBD_1_Piliocolobus_badius,(CAN_1_Colobus_angolensis_palli,(CGU_7_Colobus_guereza,CPO_2_Colobus_polykomos)69)65)1)0)3)3)66,(MSY_3_Macaca_sylvanus,(MAC_1_Macaca_arctoides,MTH_3_Macaca_thibetana)23)63)11)0,((MSI_7_Macaca_silenus,((MNE_5_Macaca_nemestrina,MMA_14_Macaca_mulatta)7,((Moc_1_Macaca_orchreata,MCY_3_Macaca_cyclopis)7,(MTO_6_Macaca_tonkeana,MNG_3_Macaca_nigra)4)0)0)0,(MFS_2_Macaca_fuscata,(MFA_18_Macaca_fascicularis,((CMO_2_Cercopithecus_mona,ANI_1_Allenopithecus_nigroviri)2,((CDA_3_Cercopithecus_diana,(CAB_1_Cercopithecus_albogulari,EPA_9_Erythrocebus_patas)3)1,(CIH_1_Cercopithecus_lhoesti,((CCE_1_Cercopithecus_cephus,(CSB_1_Chlorocebus_sabaeus,(CAE_8_Chlorocebus_aethiops,CAE_4_Chlorocebus_cynosuros)28)67)2,((CAS_1_Cercopithecus_ascanius_s,CHH_1_Cercopithecus_hamlyni_ha)24,(CWW_1_Cercopithecus_wolfi_wolf,(CMT_1_Cercopithecus_mitis,CPP_1_Cercopithecus_petaurista)2)0)0)0)0)0)55)4)0)2)3)40)12)2,(MOG_1_Miopithecus_ogouensis,PAN_10_Papio_anubis)5)66)64)1)1)0)7); "; // result will be an iterator over tuples containing the start and end indices for each match in the string let result = regex.captures_iter(string); for mat in result { println!("{:?}", mat); } }

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 Rust, please visit: https://docs.rs/regex/latest/regex/