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

/
/

Test String

Code Generator

Generated Code

package main import ( "regexp" "fmt" ) func main() { var re = regexp.MustCompile(`^(?:(?:http|https|ftp|news)[:][\/]{2})?(?:www[\.])?(?:(?:[%][2-6][0-9a-fA-F]|[%][7][0-9a-eA-E]|[a-zA-Z0-9\-\._~])+)?(?:[\.]abogado|academy|accountants|active|actor|adult|aero|agency|airforce|app|archi|army|associates|attorney|auction|audio|autos|band|bar|bar|bargains|beer|best|bid|bike|bio|biz|black|blackfriday|blog|blue|boo|boutique|build|builders|business|buzz|cab|camera|camp|cancerresearch|capital|cards|care|career|careers|casa|cash|catering|center|ceo|channel|cheap|christmas|church|city|claims|cleaning|click|clinic|clothing|club|coach|codes|coffee|college|com|community|company|computer|condos|construction|consulting|contractors|cooking|cool|coop|country|credit|creditcard|cricket|cruises|dad|dance|dating|day|deals|degree|delivery|democrat|dental|dentist|desi|diamonds|diet|digital|direct|directory|discount|domains|eat|edu|education|email|energy|engineer|engineering|enterprises|equipment|esq|estate|events|exchange|expert|exposed|fail|farm|fashion|feedback|finance|financial|fish|fishing|fitness|flights|florist|flowers|fly|foo|forsale|foundation|fund|furniture|futbol|gallery|garden|gift|gifts|gives|glass|global|gop|gov|graphics|gratis|green|gripe|guide|guitars|guru|haus|healthcare|help|here|hiphop|hiv|holdings|holiday|homes|horse|host|hosting|house|how|immo|immobilien|industries|info|ing|ink|institute|institute|insure|int|international|investments|jetzt|jobs|juegos|kaufen|kim|kitchen|land|lawyer|lease|legal|lgbt|life|lighting|limited|limo|link|loans|lotto|ltda|luxe|luxury|maison|management|market|marketing|media|meet|meme|memorial|menu|mil|mobi|moda|moe|money|mortgage|motorcycles|mov|museum|name|navy|net|network|new|ngo|ninja|ong|onl|ooo|org|organic|partners|parts|party|pharmacy|photo|photography|photos|physio|pics|pictures|pink|pizza|place|plumbing|poker|porn|post|press|pro|productions|prof|properties|property|pub|qpon|realtor|recipes|red|rehab|reise|reisen|reit|ren|rentals|repair|report|republican|rest|rest|restaurant|reviews|rich|rip|rocks|rodeo|rsvp|sarl|schule|science|services|sexy|shiksha|shoes|singles|social|software|solar|solutions|soy|space|supplies|supply|support|surf|surgery|systems|tattoo|tax|technology|tel|tienda|tips|tires|today|tools|top|town|toys|trade|training|travel|university|uno|vacations|ventures|versicherung|vet|viajes|villas|vision|vodka|vote|voting|voto|voyage|wang|watch|webcam|website|wed|wedding|whoswho|wiki|work|works|world|wtf|xxx|xyz|yoga|zone)(?:[\.](?:ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|bq|br|bs|bt|bv|bw|by|bz|bzh|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cw|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|za|zm|zw))?(?:[\/](?:[%][2-6][0-9a-fA-F]|[%][7][0-9a-eA-E]|[a-zA-Z0-9\-\._~]+)?(?:(?:[%][2-6][0-9a-fA-F]|[%][7][0-9a-eA-E]|[a-zA-Z0-9\-\._~])+)?)?(?:(?:[#](?:[]%][2-6][0-9a-fA-F]|[%][7][0-9a-eA-E]|[a-zA-Z0-9\-\._~])+)|(?:[?][=](?:[%][2-6][0-9a-fA-F]|[%][7][0-9a-eA-E]|[a-zA-Z0-9\-\._~])+))?$`) var str = `` 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/