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

package main import ( "regexp" "fmt" ) func main() { var re = regexp.MustCompile(`(?m)^source=(?P<pg_db_name>[^\s]+)\s*addon=(?P<addon_name>[^\s]+)\s*sample#current_transaction=(?P<transactionID>[^\s]+)\s*sample#db_size=(?P<db_size>[^\s]+)\s*sample#tables=(?P<numebr_of_tables>[^\s]+)\s*sample#active-connections(?P<numebr_of_active_conenctions>[^\s]+)\ssample#waiting-connections=(?P<numebr_of_waiting_conenctions>[^\s]+)\s*sample#index-cache-hit-rate=(?P<index_cache_hit_rate>[^\s]+)\s*sample#table-cache-hit-rate=(?P<table_cache_hit_rate>[^\s]+)\s*sample#load-avg-1m=(?P<load_avg_1m>[^\s]+)\s*sample#load-avg-5m=(?P<load_avg_5m>[^\s]+)\s*sample#load-avg-15m=(?P<load_avg_15m>[^\s]+)\s*sample#read-iops=(?P<Number_read_ops>[^\s]+)\s*sample#write-iops=(?P<Number_write_ops>[^\s]+)\s*sample#tmp-disk-used=(?P<tmp_disk_used>[^\s]+)\s*sample#tmp-disk-available=(?P<tmp_disk_available>[^\s]+)\s*sample#memory-total=(?P<total_memory>[^\s]+)\s*sample#memory-free=(?P<free_memory>[^\s]+)\s*sample#memory-cached=(?P<cached_memory>[^\s]+)\s*sample#memory-postgres=(?P<postgres_memory>[^\s]+)`) var str = `source=HEROKU_POSTGRESQL_CYAN addon=postgresql-parallel-49130 sample#current_transaction=1491116935 sample#db_size=70416175775bytes sample#tables=172 sample#active-connections=173 sample#waiting-connections=0 sample#index-cache-hit-rate=0.99768 sample#table-cache-hit-rate=0.99892 sample#load-avg-1m=0.26125 sample#load-avg-5m=0.205 sample#load-avg-15m=0.2175 sample#read-iops=4.0167 sample#write-iops=62.383 sample#tmp-disk-used=33849344 sample#tmp-disk-available=72944943104 sample#memory-total=62879916kB sample#memory-free=578624kB sample#memory-cached=57198556kB sample#memory-postgres=1246028kB` for i, match := range re.FindAllString(str, -1) { fmt.Println(match, "found at index", i) } }

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/