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

/
/
gm

Test String

Code Generator

Generated Code

$re = '/\.populate_tasks\[(arc|buck|build|hg|phabricator|source_control),/m'; $str = '── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[arc,diff] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[arc,fix] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[arc,focus] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[arc,lint] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[arc,pull] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[arc,refocus] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[buck,build] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[buck,install] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[buck,project] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[buck,run] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[buck,test] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[build,arc_rebuild] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[build,buck_build] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[build,entschema] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[build,fbios_noextensions] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[build,instagram_ios_noextensions] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[build,messenger_ios_noextensions] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[build,multifeed] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[build,unicorn] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[build,wakizashi] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[build,wakizashi_s2p] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[devserver,arc_fix] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[devserver,fixmyserver] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[devserver,flow_oom] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[devserver,hack_oom] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[devserver,hhserver_oom] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[hack,hh_healthy_minutes] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[hg,amend] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[hg,bookmarks] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[hg,branch] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[hg,commit] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[hg,diff] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[hg,log] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[hg,pull] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[hg,rebase] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[hg,smartlog] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[hg,status] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[hg,update] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[ide,flow_check] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[ide,flow_init] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[ide,hh_full_check] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[ide,hh_lazy_check] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[ide,hh_server_init] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[ide,intellij_file_to_intellisense] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[ide,intellij_project_to_intellisense] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[land,clean_lands] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[land,landcastle] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[phabricator,diffusion_pageload] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[phabricator,gql_client_duration] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[phabricator,gql_mutation_duration] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[phabricator,jf_submit_set_dependencies] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[phabricator,jf_submit_set_diffproperty] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[phabricator,jf_submit_total_elapsed] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[phabricator,jf_submit_update_diff] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[phabricator,jf_submit_update_revision] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[presto,adhoc_queue] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[source_control,hg] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[source_control,jellyfish] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[test,local_www] ── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[test,mobilelab]'; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

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 PHP, please visit: http://php.net/manual/en/ref.pcre.php