Regular Expressions 101

Save & Share

  • Regex Version: ver. 4
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

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

package main import ( "regexp" "fmt" ) func main() { var re = regexp.MustCompile(`(?m)^source=(?P<pg_db_name>[^\s]+)\s*addon=(?P<pg_addon_name>[^\s]+)\s*sample#current_transaction=(?P<pg_transactionID>[^\s]+)\s*sample#db_size=(?P<pg_db_size>[^\s]+)\s*sample#tables=(?P<pg_numebr_of_tables>[^\s]+)\s*sample#active-connections(?P<pg_number_of_active_connections>[^\s]+)\ssample#waiting-connections=(?P<pg_number_of_waiting_connections>[^\s]+)\s*sample#index-cache-hit-rate=(?P<pg_index_cache_hit_rate>[^\s]+)\s*sample#table-cache-hit-rate=(?P<pg_table_cache_hit_rate>[^\s]+)\s*sample#load-avg-1m=(?P<pg_load_avg_1m>[^\s]+)\s*sample#load-avg-5m=(?P<pg_load_avg_5m>[^\s]+)\s*sample#load-avg-15m=(?P<pg_load_avg_15m>[^\s]+)\s*sample#read-iops=(?P<pg_read_iops>[^\s]+)\s*sample#write-iops=(?P<pg_write_ops>[^\s]+)\s*sample#tmp-disk-used=(?P<pg_tmp_disk_used>[^\s]+)\s*sample#tmp-disk-available=(?P<pg_tmp_disk_available>[^\s]+)\s*sample#memory-total=(?P<pg_total_memory>[^\s]+)\s*sample#memory-free=(?P<pg_free_memory>[^\s]+)\s*sample#memory-cached=(?P<pg_cached_memory>[^\s]+)\s*sample#memory-postgres=(?P<pg_memory>[^\s]+)\s*sample#follower-lag-commits=(?P<follower_lag_commits>[^$]+)`) 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 source=HEROKU_POSTGRESQL_YELLOW addon=postgresql-rugged-78838 sample#current_transaction=1624380465 sample#db_size=91403178655bytes sample#tables=176 sample#active-connections=6 sample#waiting-connections=0 sample#index-cache-hit-rate=0.99483 sample#table-cache-hit-rate=0.7344 sample#load-avg-1m=0.0075 sample#load-avg-5m=0.005 sample#load-avg-15m=0 sample#read-iops=0 sample#write-iops=0.59322 sample#tmp-disk-used=33849344 sample#tmp-disk-available=72944943104 sample#memory-total=31398060kB sample#memory-free=421344kB sample#memory-cached=29831456kB sample#memory-postgres=18036kB sample#follower-lag-commits=0` 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/