Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • 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
  • 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 = '/^.*?(?P<body>{.*})/m'; $str = '{"channel":"crm_process_booking_log","log_type":"DEBUG","index_name":"crm_process_booking_log","index_type":"crm_process_booking_log","error_type":0,"message":{"data":{"STEP":"slot_details","slotDetail":{"stm_id":"684178718","time":"14:30:00","end_time":"15:30:00","locality_id":0,"booking_id":0,"freeze_count":0,"date":"2024-02-07","user_id":0,"collection_center_id":0,"b2b_zone_id":0,"zone_id":53,"sample_type_id":1,"isavailable":1,"isactive":1,"set_name":"set5","is_peak_hours":0,"source":"crm","order_group_id":0,"old_zone_id":0,"samplecollector_id":0,"old_set_name":"","phlebo_name":"","assign_time":"0000-00-00 00:00:00","freeze":0,"freeze_date":"0000-00-00 00:00:00","payment":0,"locusStatus":0,"lat":"","lng":"","dropTaskStatus":0,"autoAssignStatus":0,"pickup_type":"home","service_id":0,"consultation_id":0,"channel_type":0,"channel_user":0,"vendor_user_id":"","created_at":"2024-02-05 12:56:10","updated_at":"2024-02-05 12:56:10","reference_stm_id":0,"phlebo_id":0},"amzn_trace_id":"Root=1-65c33f1c-29fe535658001b076140677c"},"calling_trace":{"file":"\\/var\\/www\\/newcrm-t25\\/application\\/controllers\\/crmuser\\/crmorder.php","line":2112,"function":"addProcessBookingLog","class":"Enterprise_logger"}},"amzn_trace_id":"Root=1-65c33f1c-29fe535658001b076140677c","nginx_request_id":"c93176430784c9dd4e32e35541e6e31a","timestamp":"2024-02-07 13:58:12"}'; 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