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
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
No Match

`
`

Test String

Code Generator

Generated Code

package main import ( "regexp" "fmt" ) func main() { var re = regexp.MustCompile(`(?P<timestamp>\d{2}\/\d{2}\/\d{4}\s+\d{2}\:\d{2}\:\d{2}\.\d{1,4}\s*\+\d{2}\:\d{2})\s*-\s*\[(?P<severity>[A-Z]+)\]\s*-\s*\[(?P<subsystem>[^\]]+)\]\s*-\s*(?P<message>.*)`) var str = `01/04/2021 15:29:55.2955 +03:00 - [INFO] - [w3wp/LPAPI-Last Casino/153] - AppsFlyerPostback?re_targeting_conversion_type=&is_retargeting=false&app_id=com.rocketplay.luckyplay&platform=android&event_type=in-app-event&attribution_type=organic&event_time=2021-04-01 12:29:59&event_time_selected_timezone=2021-04-01 05:29:59.349-0700&event_name=app-login&event_value={"":1}&currency=USD&selected_currency=USD&revenue_in_selected_currency=&cost_per_install=&click_time=&click_time_selected_timezone=&install_time=2021-02-22 15:51:48&install_time_selected_timezone=2021-02-22 07:51:48.419-0800&agency=&media_source=Organic&campaign=&fb_campaign_id=&fb_campaign_name=&fb_adset_name=&fb_adset_id=&fb_adgroup_id=&fb_adgroup_name=&af_siteid=&country_code=US&city=Lady Lake&ip=8.24.83.231&wifi=true&language=English&appsflyer_device_id=1614007442730-8802774993131726691&customer_user_id=&android_id=&imei=&advertising_id=e7f5a367-3a47-43b3-a0d7-34ab582db7f3&mac=&device_brand=google&device_model=Acer Chromebook 15 (CB515-1H, CB515-1HT)&os_version=9&sdk_version=v4.6.0&app_version=5.3.7&operator=&carrier=&af_sub1=&af_sub2=&af_sub3=&af_sub4=&af_sub5=&click_url=&http_referrer=&app_name=Lucky Play Casino – Free Las Vegas Slots Machines&download_time=2021-02-22 15:24:00&download_time_selected_timezone=2021-02-22 07:24:00.000-0800&af_keywords=&bundle_id=com.rocketplay.luckyplay&attributed_touch_type=&attributed_touch_time= ` if len(re.FindStringIndex(str)) > 0 { fmt.Println(re.FindString(str),"found at index",re.FindStringIndex(str)[0]) } }

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 Golang, please visit: https://golang.org/pkg/regexp/