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 = "(?s)\[(?P<stanza_name>[0-9a-zA-Z-_\ ]*?)\](?P<text>.*?)\n\n" Local $sString = "[inv_records]" & @CRLF & _ "search = index=apm_main eventtype=da_host sourcetype=snpm:ipact:kvp2" & @CRLF & _ "" & @CRLF & _ "[equipment-InterfaceStatsLogRecord]" & @CRLF & _ "search = eventtype=sam_events (ds=equipment.InterfaceStatsLogRecord OR ds=equipment.InterfaceAdditionalStats)" & @CRLF & _ "" & @CRLF & _ "[inv_avc]" & @CRLF & _ "search = eventtype=inv_records source="/data/snpm/splunk/inventory/*_AVC_*" ACCESS_SERVICE_TECH_TYPE="*"\" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "[inv_cvc]" & @CRLF & _ "search = eventtype=inv_records source="/data/snpm/splunk/inventory/*SNPM_CVC_*"" & @CRLF & _ "" & @CRLF & _ "[inv_device_links]" & @CRLF & _ "search = eventtype=inv_records source="/data/snpm/splunk/inventory/*_DEVICE_LINKS_*"\" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "[inv_nni]" & @CRLF & _ "search = eventtype=inv_records source="/data/snpm/splunk/inventory/*_NNI_*" NOT source="*IPACT_SNPM_NNI_LINKS*"\" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "[inv_rsp_cvc_interconnect_svc]" & @CRLF & _ "search = eventtype=inv_records source="/data/snpm/splunk/inventory/*_RSP_CVC_INTERCONNECT_SVC_*"\" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "[inv_sites_poi]" & @CRLF & _ "search = eventtype=inv_records source="/data/snpm/splunk/inventory/*_SITES_POI_*"\" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "[service-CombinedForwardingPlaneQueueGroupServiceIngressLogRecord]" & @CRLF & _ "search = eventtype=sam_events ds=service.CombinedForwardingPlaneQueueGroupServiceIngressLogRecord" & @CRLF & _ "" & @CRLF & _ "[sam_events]" & @CRLF & _ "search = index=apm_main eventtype=da_host sourcetype=snpm:sam:kvp*" & @CRLF & _ "" & @CRLF & _ "[service-CombinedQueueGroupEgressLogRecord]" & @CRLF & _ "search = eventtype=sam_events ds=service.CombinedQueueGroupEgressLogRecord" & @CRLF & _ "" & @CRLF & _ "[service-ServiceEgressOctetsLogRecord]" & @CRLF & _ "search = eventtype=sam_events ds="service.ServiceEgressOctetsLogRecord"" & @CRLF & _ "" & @CRLF & _ "[summary_snr_histogram]" & @CRLF & _ "search = (index="summary_apm_snr" eventtype=search_head) OR (eventtype="summary_data") snpm_type="SNR UTIL"" & @CRLF & _ "" & @CRLF & _ "[summary_cvc_util]" & @CRLF & _ "search = (index="summary_apm_cvc" eventtype=search_head) OR (eventtype="summary_data") snpm_type="CVC UTIL"" & @CRLF & _ "" & @CRLF & _ "[savvi_log]" & @CRLF & _ "search = index=apm_main eventtype=da_host (source="/var/log/savvi/*" OR source="/opt/titan/log/*")" & @CRLF & _ "" & @CRLF & _ "[summary_data]" & @CRLF & _ "search = (index="apm_snpm" eventtype=search_head) search_name="*summary*"" & @CRLF & _ "" & @CRLF & _ "[summary_ipact]" & @CRLF & _ "search = (index="summary_apm_ipact" eventtype=search_head) OR (eventtype="summary_data") snpm_type="IPACT_CVC"" & @CRLF & _ "" & @CRLF & _ "[summary_ipact_avc]" & @CRLF & _ "search = (index="summary_apm_ipact" eventtype=search_head) OR (eventtype="summary_data") snpm_type="IPACT_AVC"" & @CRLF & _ "" & @CRLF & _ "[summary_cvc_bh]" & @CRLF & _ "search = (index="summary_apm_cvc" eventtype=search_head) OR (eventtype="summary_data") snpm_type="CVC BH"" & @CRLF & _ "" & @CRLF & _ "[summary_enni_group]" & @CRLF & _ "search = (index="summary_apm_enni" eventtype=search_head) OR (eventtype="summary_data") snpm_type="ENNI UTIL GRP"" & @CRLF & _ "" & @CRLF & _ "[summary_enni_port]" & @CRLF & _ "search = (index="summary_apm_enni" eventtype=search_head) OR (eventtype="summary_data") snpm_type="ENNI UTIL PRT"" & @CRLF & _ "" & @CRLF & _ "[sam_enni_port]" & @CRLF & _ "search = (eventtype=sam_events ds="equipment.InterfaceAdditionalStatsLogRecord" displayedName="Port*" NOT (suspect=true) )" & @CRLF & _ "" & @CRLF & _ "[sam_enni_group]" & @CRLF & _ "search = (eventtype=sam_events ds="equipment.InterfaceAdditionalStatsLogRecord" displayedName="Lag*" NOT (suspect=true) )" & @CRLF & _ "" & @CRLF & _ "[summary_sanitized]" & @CRLF & _ "search = ( eventtype=summary_cvc_util inboundUtilizationPcnt>= 0 inboundUtilizationPcnt< 200 ) OR\" & @CRLF & _ "( eventtype=summary_snr_histogram utilPcnt>=0 utilPcnt<200 ) OR\" & @CRLF & _ "( eventtype=summary_enni* (rx_utilPcnt>=0 rx_utilPcnt<200 ) (tx_utilPcnt>=0 tx_utilPcnt<200 )) OR\" & @CRLF & _ "( eventtype=summary_cvc_util NOT inboundUtilizationPcnt=* ) OR\" & @CRLF & _ "( eventtype=summary_snr_histogram NOT utilPcnt=* ) OR\" & @CRLF & _ "( eventtype=summary_enni* (NOT rx_utilPcnt=*) OR (NOT tx_utilPcnt=*))" & @CRLF & _ "" & @CRLF & _ "[sam_cvc_downstream_1_1]" & @CRLF & _ "search = eventtype=sam_events ds=service.CombinedForwardingPlaneQueueGroupServiceIngressLogRecord" & @CRLF & _ "" & @CRLF & _ "[sam_cvc_downstream_n_1]" & @CRLF & _ "search = eventtype=sam_events ds="service.ServiceEgressOctetsLogRecord" svcId=* (policerId=6) NOT (statMode=no-stats)" & @CRLF & _ "" & @CRLF & _ "[sam_cvc_upstream_1_1]" & @CRLF & _ "search = eventtype=sam_events ds="service.ServiceEgressOctetsLogRecord" sapId="lag-*" NOT statMode="no-stats"" & @CRLF & _ "" & @CRLF & _ "[sam_cvc_upstream_n_1]" & @CRLF & _ "search = eventtype=sam_events ds="service.ServiceEgressOctetsLogRecord" queueId=6 sapId="lag*"" & @CRLF & _ "" & @CRLF & _ "[summary_filter]" & @CRLF & _ "search = ( eventtype=summary_cvc_util inboundUtilizationPcnt < 0 OR inboundUtilizationPcnt> 200 ) OR\" & @CRLF & _ "( eventtype=summary_snr_histogram utilPcnt < 0 OR utilPcnt >200 ) OR\" & @CRLF & _ "( eventtype=summary_enni* (rx_utilPcnt < 0 OR rx_utilPcnt>200 ) OR (tx_utilPcnt<0 tx_utilPcnt>200 ))" & @CRLF & _ "" & @CRLF & _ "[inv_nni_links]" & @CRLF & _ "search = eventtype=inv_records source="*IPACT_SNPM_NNI_LINKS*"" & @CRLF & _ "" & @CRLF & _ "[sam_ltss]" & @CRLF & _ "priority = 5" & @CRLF & _ "search = index=apm_main eventtype=ltss_da_host ds=service.ServiceEgressOctetsLogRecord" & @CRLF & _ "" & @CRLF & _ "[ltss_inv_sites_poi]" & @CRLF & _ "search = eventtype=ltss_inv_records source="*_SITES_PO*"\" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "[ltss_inv_rsp_cvc_interconnect_svc]" & @CRLF & _ "search = eventtype=ltss_inv_records source="*_RSP_CVC_INTERCONNECT_SVC_*"\" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "[ltss_inv_records]" & @CRLF & _ "priority = 5" & @CRLF & _ "search = index=apm_main sourcetype = snpm:ipact:kvp2 eventtype=ltss_da_host" & @CRLF & _ "" & @CRLF & _ "[ltss_inv_nni_links]" & @CRLF & _ "search = eventtype=ltss_inv_records source="*IPACT_SNPM_NNI_LINKS*"" & @CRLF & _ "" & @CRLF & _ "[ltss_inv_nni]" & @CRLF & _ "search = eventtype=ltss_inv_records source="*IPACT_SNPM_NNI*" NOT source="*IPACT_SNPM_NNI_LINKS*"\" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "[ltss_inv_device_links]" & @CRLF & _ "search = eventtype=ltss_inv_records source="*IPACT_SNPM_DEVICE_LINKS*"\" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "[ltss_inv_cvc]" & @CRLF & _ "search = eventtype=ltss_inv_records source="*IPACT_SNPM_CVC*"" & @CRLF & _ "" & @CRLF & _ "[ltss_inv_avc]" & @CRLF & _ "search = eventtype=ltss_inv_records source="*IPACT_SNPM_AVC*" ACCESS_SERVICE_TECH_TYPE="Satellite"\" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "[ltss_summary_ipact_avc]" & @CRLF & _ "search = eventtype=ltss_summary_data index="summary_apm_ltss_ipact" snpm_type="IPACT_AVC_LTSS"" & @CRLF & _ "" & @CRLF & _ "[ltss_summary_cvc_util]" & @CRLF & _ "search = eventtype=ltss_summary_data index=summary_apm_ltss_cvc snpm_type = "LTSS CVC UTIL" snpm_version="V1.3"" & @CRLF & _ "" & @CRLF & _ "[ltss_summary_avc_util_daily]" & @CRLF & _ "search = eventtype=ltss_summary_data index=summary_apm_ltss_avc_daily snpm_type = "LTSS AVC UTIL DAILY" snpm_version="V1.5.1"" & @CRLF & _ "" & @CRLF & _ "[ltss_summary_avc_util]" & @CRLF & _ "search = eventtype=ltss_summary_data index=summary_apm_ltss_avc snpm_type = "LTSS AVC UTIL" snpm_version=V1.5" & @CRLF & _ "" & @CRLF & _ "[ltss_summary_cvc_util_breach]" & @CRLF & _ "priority = 5" & @CRLF & _ "search = eventtype=ltss_summary_data index=summary_apm_ltss_cvc snpm_type="CVC UTIL BREACH"" & @CRLF & _ "" & @CRLF & _ "[ltss_summary_short_term]" & @CRLF & _ "search = eventtype=ltss_summary_data index=summary_apm_ltss snpm_type = "LTSS SHORT TERM"" & @CRLF & _ "" & @CRLF & _ "[ltss_summary_fsd_fsr]" & @CRLF & _ "search = eventtype=ltss_summary_data index=summary_apm_ltss snpm_type="LTSS FSD FSR DAILY"" & @CRLF & _ "" & @CRLF & _ "[ltss_summary_data]" & @CRLF & _ "search = (index=summary_apm_ltss* (eventtype=search_head))" & @CRLF & _ "" & @CRLF & _ "[ltss_summary_beam_util]" & @CRLF & _ "search = eventtype=ltss_summary_data snpm_type = "LTSS BEAM UTIL" snpm_version="V1.5.2"" & @CRLF & _ "" & @CRLF & _ "[search_head]" & @CRLF & _ "search = (host=svsss0000003np-heavy OR host=svsss0000203np-heavy)" & @CRLF & _ "" & @CRLF & _ "[da_host]" & @CRLF & _ "search = (host=svapm0000004np)" & @CRLF & _ "" & @CRLF & _ "[ltss_da_host]" & @CRLF & _ "search = (host=svapm0000004np)" & @CRLF & _ "" & @CRLF & _ "[sam_aas]" & @CRLF & _ "priority = 5" & @CRLF & _ "search = index=apm_main host=svapm0000008ee sourcetype="snpm:sam:kvp2" ds="service.ServiceEgressOctetsLogRecord"" & @CRLF & _ "" & @CRLF & _ "[aas_summary_enni_group]" & @CRLF & _ "priority = 5" & @CRLF & _ "search = (index="summary_apm_enni" eventtype=search_head) OR (eventtype="aas_summary_data") snpm_type="AAS ENNI UTIL GRP"" & @CRLF & _ "" & @CRLF & _ "[aas_avc_status_daily]" & @CRLF & _ "search = index=apm_snpm snpm_type="AAS_IPACT_AVC_STATUS"" & @CRLF & _ "" & @CRLF & _ "[snpm_inv_avc]" & @CRLF & _ "search = eventtype=snpm_inv_records source="*IPACT_SNPM_AVC*"" & @CRLF & _ "" & @CRLF & _ "[snpm_inv_cvc]" & @CRLF & _ "search = eventtype=snpm_inv_records source="*IPACT_SNPM_CVC*"" & @CRLF & _ "" & @CRLF & _ "[snpm_inv_rsp_cvc_interconnect_svc]" & @CRLF & _ "search = eventtype=snpm_inv_records source="*_RSP_CVC_INTERCONNECT_SVC_*"" & @CRLF & _ "" & @CRLF & _ "[snpm_inv_nni]" & @CRLF & _ "search = eventtype=snpm_inv_records source="*IPACT_SNPM_NNI*" NOT source="*IPACT_SNPM_NNI_LINKS*"" & @CRLF & _ "" & @CRLF & _ "[snpm_inv_records]" & @CRLF & _ "search = index=apm_main sourcetype=snpm:ipact:kvp2 eventtype=da_host" & @CRLF & _ "" & @CRLF & _ "[snpm_inv_sites_poi]" & @CRLF & _ "search = eventtype=snpm_inv_records source="*_SITES_PO*"" & @CRLF & _ "" & @CRLF & _ "[snpm_summary_ipact_avc]" & @CRLF & _ "search = index="summary_apm_ipact" snpm_info="Ipact Summary for AVC SNPM" (eventtype=search_head)" & @CRLF & _ "" & @CRLF & _ "[aes_summary_ipact_avc]" & @CRLF & _ "search = index="summary_apm_ipact" snpm_info="Ipact Summary for AVC SNPM" ACCESS_SERVICE_TECH_TYPE="Fibre" (eventtype=search_head)" & @CRLF & _ "" & @CRLF & _ "[aes_avc_status]" & @CRLF & _ "search = index="summary_apm_ipact" snpm_type="SNPM_IPACT_AVC_STATUS" ACCESS_SERVICE_TECH_TYPE="Fibre" (eventtype=search_head)" & @CRLF & _ "" & @CRLF & _ "[aes_summary_ipact_cvc]" & @CRLF & _ "search = index="summary_apm_ipact" snpm_type = "IPACT_CVC_NNI_AES" (eventtype=search_head)" & @CRLF & _ "" & @CRLF & _ "[aes_cvc_status]" & @CRLF & _ "search = index="summary_apm" snpm_type="IPACT_CVC_STATUS_AES" (eventtype=search_head)" & @CRLF & _ "" & @CRLF & _ "[aes_nni_status_summary]" & @CRLF & _ "search = index="summary_apm" snpm_type="NNI_STATUS_AES" (eventtype=search_head)" & @CRLF & _ "" & @CRLF & _ "[aes_inni_summary_util_discard_status_combined]" & @CRLF & _ "search = index="summary_apm" snpm_type="inni_summary_combined_aes" (eventtype=search_head)" & @CRLF & _ "" & @CRLF & _ "[aes_inni_summary]" & @CRLF & _ "search = index="summary_apm" snpm_type="inni_group_summary_aes" (eventtype=search_head)" & @CRLF & _ "" & @CRLF & _ "[aes_enni_summary]" & @CRLF & _ "search = index="summary_apm" snpm_type="enni_group_summary_aes" (eventtype=search_head)" & @CRLF & _ "" & @CRLF & _ "[sam_inni_group]" & @CRLF & _ "search = (eventtype=sam_events ds="equipment.InterfaceAdditionalStatsLogRecord" displayedName="Lag*" NOT (suspect=true) )" & @CRLF & _ "" & @CRLF & _ "[aas_sam_inni_group]" & @CRLF & _ "search = (eventtype=aas_sam_events ds="equipment.InterfaceAdditionalStatsLogRecord" displayedName="Lag*" NOT (suspect=true) )\" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "[aas_sam_events]" & @CRLF & _ "priority = 5" & @CRLF & _ "search = index=apm_main eventtype=da_host sourcetype=snpm:sam:kvp*" & @CRLF & _ "" & @CRLF & _ "[aas_sam_enni_group]" & @CRLF & _ "priority = 5" & @CRLF & _ "search = eventtype=aas_sam_events ds="equipment.InterfaceAdditionalStatsLogRecord" displayedName="Lag*" NOT (suspect=true)" & @CRLF & _ "" & @CRLF & _ "[aes_egress_drop]" & @CRLF & _ "search = eventtype=sam_events ds="Service.NetworkEgressOctetsLogRecord"" & @CRLF & _ "" & @CRLF & _ "[aes_egress_discard]" & @CRLF & _ "search = index="summary_apm" snpm_type="aes_egress_discard"" & @CRLF & _ "" & @CRLF & _ "[ltss_summary_fsd_fsr_enhance]" & @CRLF & _ "search = eventtype=ltss_summary_data index=summary_apm_ltss snpm_type="LTSS FSD FSR DAILY ENHANCE"" & @CRLF & _ "" & @CRLF & _ "[ltss_summary_short_term_enhance]" & @CRLF & _ "search = eventtype=ltss_summary_data index=summary_apm_ltss snpm_type = "LTSS SHORT TERM ENHANCE"" & @CRLF & _ "" & @CRLF & _ "[aes_summary_ipact_avc_device]" & @CRLF & _ "search = index="summary_apm_ipact" snpm_info="Ipact Summary for AVC SNPM & Device Links" ACCESS_SERVICE_TECH_TYPE="Fibre" (eventtype=search_head)" & @CRLF & _ "" & @CRLF & _ "[aes_avc_util_discard_summary]" & @CRLF & _ "search = index="summary_apm_avc" snpm_type ="AES AVC UTIL & DISCARD ALL" (eventtype=search_head)" & @CRLF & _ "" & @CRLF & _ "[ltss_summary_ipact_avc_30mintest]" & @CRLF & _ "search = eventtype=ltss_summary_data index="summary_apm_ltss_ipact" snpm_type="IPACT_AVC_LTSS_30MIN"" & @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