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 single character of: a, b, c or d
    [[ab][cd]]
  • 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]
  • Character class intersection
    [\w&&[^\d]]
  • 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

"
"
g

Test String

Code Generator

Generated Code

package main import ( "regexp" "fmt" ) func main() { var re = regexp.MustCompile(`[:]\s(\".*\")|\d+`) var str = `{ "code": 0, "data": { "album": { "count": 2, "itemlist": [ { "docid": "24100646", "id": "24100646", "mid": "002mPgSG01LLtu", "name": "无名的人", "pic": "http://y.gtimg.cn/music/photo_new/T002R180x180M000002mPgSG01LLtu_1.jpg", "singer": "毛不易" }, { "docid": "3834888", "id": "3834888", "mid": "0026ttFc17IeE3", "name": "无问", "pic": "http://y.gtimg.cn/music/photo_new/T002R180x180M0000026ttFc17IeE3_1.jpg", "singer": "毛不易" } ], "name": "专辑", "order": 2, "type": 3 }, "mv": { "count": 2, "itemlist": [ { "docid": "1449642", "id": "1449642", "mid": "001UwAbv4H9QVZ", "name": "牧马城市", "singer": "毛不易", "vid": "k002671le5d" }, { "docid": "1352908", "id": "1352908", "mid": "003bjsSu20ltwY", "name": "像我这样的人", "singer": "毛不易", "vid": "y0026hr4b5e" } ], "name": "MV", "order": 3, "type": 4 }, "singer": { "count": 2, "itemlist": [ { "docid": "1507534", "id": "1507534", "mid": "001BHDR33FZVZ0", "name": "毛不易", "pic": "http://y.gtimg.cn/music/photo_new/T001R150x150M000001BHDR33FZVZ0_3.jpg", "singer": "毛不易" }, { "docid": "4417724", "id": "4417724", "mid": "000pEm1i1BkmuD", "name": "毛不易的留声机", "pic": "http://y.gtimg.cn/music/photo_new/T001R150x150M000000pEm1i1BkmuD_1.jpg", "singe": "毛不易的留声机" } ], "name": "歌手", "order": 1, "type": 2 }, "song": { "count": 4, "itemlist": [ { "docid": "203514624", "id": "203514624", "mid": "00375L600p9sxv", "name": "像我这样的人", "singer": "毛不易" } { "docid": "203451421", "id": "203451421", "mid": "003kLvu04bLGzi", "name": "消愁", "singer": "毛不易" } { "docid": "213224236", "id": "213224236", "mid": "000uhMwj387EBp", "name": "牧马城市", "singer": "毛不易" } { "docid": "336582682", "id": "336582682", "mid": "002QhULf16tWw1", "name": "无名的人", "singer": "毛不易" } ], "name": "单曲", "order": 0, "type": 1 } }, "subcode": 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/