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 = '/(?<id>[^\|]*)\|(?<action>[^\|]*)\|(?<date_create>[^\|]*)\|(?<actor_type>[^\|]*)\|(?<actor_user_id>[^\|]*)\|(?<actor_user_name>[^\|]*)\|(?<actor_user_email>[^\|]*)\|(?<entity_type>[^\|]*)\|(?<entity_user_id>[^\|]*)\|(?<entity_user_name>[^\|]*)\|(?<entity_user_email>[^\|]*)\|(?<entity_workspace_id>[^\|]*)\|(?<entity_workspace_name>[^\|]*)\|(?<entity_workspace_domain>[^\|]*)\|(?<entity_enterprise_id>[^\|]*)\|(?<entity_enterprise_name>[^\|]*)\|(?<entity_enterprise_domain>[^\|]*)\|(?<entity_channel_id>[^\|]*)\|(?<entity_channel_name>[^\|]*)\|(?<entity_channel_privacy>[^\|]*)\|(?<entity_channel_is_shared>[^\|]*)\|(?<entity_channel_is_org_shared>[^\|]*)\|(?<entity_app_id>[^\|]*)\|(?<entity_app_name>[^\|]*)\|(?<entity_app_is_distributed>[^\|]*)\|(?<entity_app_is_directory_approved>[^\|]*)\|(?<entity_app_scopes>[^\|]*)\|(?<entity_file_id>[^\|]*)\|(?<entity_file_name>[^\|]*)\|(?<entity_file_filetype>[^\|]*)\|(?<entity_file_title>[^\|]*)\|(?<context_type>[^\|]*)\|(?<context_location_id>[^\|]*)\|(?<context_location_name>[^\|]*)\|(?<context_location_type>[^\|]*)\|(?<context_location_domain>[^\|]*)\|(?<context_ua>[^\|]*)\|(?<context_ipaddress>[^\|]*)\|(?<details_name>[^\|]*)\|(?<details_type>[^\|]*)\|(?<details_previous_value>[^\|]*)\|(?<details_new_value>[^\|]*)\|(?<details_export_type>[^\|]*)\|(?<details_export_start_ts>[^\|]*)\|(?<details_export_end_ts>[^\|]*)\|(?<details_is_internal_integration>[^\|]*)\|(?<details_kicker_id>[^\|]*)\|(?<details_kicker_name>[^\|]*)\|(?<details_kicker_email>[^\|]*)\|(?<details_inviter_id>[^\|]*)\|(?<details_inviter_name>[^\|]*)\|?(?<details_inviter_name2>[^\|]*)\|?(?<details_inviter_email>[\w+]*) /m'; $str = 'f6c75963-192e-4cb7-b25e-aef5ca3dd7de|file_shared|02/05/2019 19:07|user|WC31RPBJ4|Saumya Khanna|Saumya.Khanna@marsh.com|file||||||||||||||||||||FFZ3JH8CV|image.png|image/png|Pasted image at 2019-02-05, 2:07 PM||EB6CVT82J|Marsh & McLennan Companies, Inc.|enterprise|mmc||||||||||||||||| 903dd3e5-6c28-49fa-bc4a-7997daa7abb5|user_channel_join|01/17/2019 20:01|user|WALL8ECLC|Mary Yao|Mary.Yao@oliverwyman.com|channel||||||||||CFGD6P552|studioculture|public|false|false|||||||||||TCX7L0SP5|NY Studio|workspace|ny-studio|Mozilla/5.0 (Windows NT 10.0.14393; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) AtomShell/3.3.3 Chrome/61.0.3163.100 Electron/2.0.7 Safari/537.36 Slack_SSB/3.3.3|167.245.255.229||INVITED||||||||||WA50E2AAX|Dustin Hughes|dustin.hughes@oliverwyman.com (?<id>[^\\|]*)\\|(?<action>[^\\|]*)\\|(?<date_create>[^\\|]*)\\|(?<actor_type>[^\\|]*)\\|(?<actor_user_id>[^\\|]*)\\|(?<actor_user_name>[^\\|]*)\\|(?<actor_user_email>[^\\|]*)\\|(?<entity_type>[^\\|]*)\\|(?<entity_user_id>[^\\|]*)\\|(?<entity_user_name>[^\\|]*)\\|(?<entity_user_email>[^\\|]*)\\|(?<entity_workspace_id>[^\\|]*)\\|(?<entity_workspace_name>[^\\|]*)\\|(?<entity_workspace_domain>[^\\|]*)\\|(?<entity_enterprise_id>[^\\|]*)\\|(?<entity_enterprise_name>[^\\|]*)\\|(?<entity_enterprise_domain>[^\\|]*)\\|(?<entity_channel_id>[^\\|]*)\\|(?<entity_channel_name>[^\\|]*)\\|(?<entity_channel_privacy>[^\\|]*)\\|(?<entity_channel_is_shared>[^\\|]*)\\|(?<entity_channel_is_org_shared>[^\\|]*)\\|(?<entity_app_id>[^\\|]*)\\|(?<entity_app_name>[^\\|]*)\\|(?<entity_app_is_distributed>[^\\|]*)\\|(?<entity_app_is_directory_approved>[^\\|]*)\\|(?<entity_app_scopes>[^\\|]*)\\|(?<entity_file_id>[^\\|]*)\\|(?<entity_file_name>[^\\|]*)\\|(?<entity_file_filetype>[^\\|]*)\\|(?<entity_file_title>[^\\|]*)\\|(?<context_type>[^\\|]*)\\|(?<context_location_id>[^\\|]*)\\|(?<context_location_name>[^\\|]*)\\|(?<context_location_type>[^\\|]*)\\|(?<context_location_domain>[^\\|]*)\\|(?<context_ua>[^\\|]*)\\|(?<context_ipaddress>[^\\|]*)\\|(?<details_name>[^\\|]*)\\|(?<details_type>[^\\|]*)\\|(?<details_previous_value>[^\\|]*)\\|(?<details_new_value>[^\\|]*)\\|(?<details_export_type>[^\\|]*)\\|(?<details_export_start_ts>[^\\|]*)\\|(?<details_export_end_ts>[^\\|]*)\\|(?<details_is_internal_integration>[^\\|]*)\\|(?<details_kicker_id>[^\\|]*)\\|(?<details_kicker_name>[^\\|]*)\\|(?<details_kicker_email>[^\\|]*)\\|(?<details_inviter_id>[^\\|]*)\\|(?<details_inviter_name>[^\\|]*)\\|(?<details_inviter_email>(\\w+))?\\|'; 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