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

/
/

Test String

Code Generator

Generated Code

const regex = /^\[(?P<thread_name>\w+\-\d+)\]\s\d\d\d\d\-\d\d\-\d\d\s\d\d:\d\d:\d\d\s\[(?P<request_id>[^,]+),(?P<global_partner_code>[^,]+),(?P<plf_code>[^,]+),(?P<request_type>[^,]+),(?P<product_type>[^,]+),\d\d\-\d\d\-\d\d\d\d\s\d\d:\d\d:\d\d,(?P<server_name>[^,]+),(?P<check_in_date>[^ ]+)\s00:00:00,(?P<check_out_date>[^ ]+)\s00:00:00,(?P<requested_currency_code>[^,]+),(?P<requested_language_code>[^,]+),(?P<error_code>[^,]+),(?P<error_desc>[^,]+),(?P<gds_processing_time>\d+),(?P<total_processing_time>\d+),(?P<pre_gds_processing_time>\d+),(?P<post_gds_processing_time>\d+),(?P<post_processing_time>\d+),(?P<response_time>\d+),(?P<property_count>\d+),(?P<opaque_rate_request_count>\d+),(?P<merchant_rate_request_count>\d+),(?P<agency_rate_request_count>\d+),(?P<cached_rate_request_count>\d+),(?P<avail_request_count>\d+),(?P<rule_request_count>\d+),(?P<on_time_request_count>\d+),(?P<late_request_count>\d+),(?P<timeout_request_count>\d+),(?P<cache_read_time>\d+),(?P<cache_update_time>\d+),(?P<business_processing_time>\d+)\]/; // Alternative syntax using RegExp constructor // const regex = new RegExp('^\\[(?P<thread_name>\\w+\\-\\d+)\\]\\s\\d\\d\\d\\d\\-\\d\\d\\-\\d\\d\\s\\d\\d:\\d\\d:\\d\\d\\s\\[(?P<request_id>[^,]+),(?P<global_partner_code>[^,]+),(?P<plf_code>[^,]+),(?P<request_type>[^,]+),(?P<product_type>[^,]+),\\d\\d\\-\\d\\d\\-\\d\\d\\d\\d\\s\\d\\d:\\d\\d:\\d\\d,(?P<server_name>[^,]+),(?P<check_in_date>[^ ]+)\\s00:00:00,(?P<check_out_date>[^ ]+)\\s00:00:00,(?P<requested_currency_code>[^,]+),(?P<requested_language_code>[^,]+),(?P<error_code>[^,]+),(?P<error_desc>[^,]+),(?P<gds_processing_time>\\d+),(?P<total_processing_time>\\d+),(?P<pre_gds_processing_time>\\d+),(?P<post_gds_processing_time>\\d+),(?P<post_processing_time>\\d+),(?P<response_time>\\d+),(?P<property_count>\\d+),(?P<opaque_rate_request_count>\\d+),(?P<merchant_rate_request_count>\\d+),(?P<agency_rate_request_count>\\d+),(?P<cached_rate_request_count>\\d+),(?P<avail_request_count>\\d+),(?P<rule_request_count>\\d+),(?P<on_time_request_count>\\d+),(?P<late_request_count>\\d+),(?P<timeout_request_count>\\d+),(?P<cache_read_time>\\d+),(?P<cache_update_time>\\d+),(?P<business_processing_time>\\d+)\\]', '') const str = `[Thread-3156] 2016-06-01 12:00:33 [20160601155602e0c02031-1464796832222-NSRLM_8_SHARC:M2_1_RTL_OP,PCLN,PCLN,AVAIL,TWEB,06-01-2016 12:00:33,ASH1-RHSE-401,06-17-2016 00:00:00,06-19-2016 00:00:00, SD,en,N/A,N/A,0,71,66,1,1,70,17,0,0,17,0,0,0,0,0,0,0,0,0] [Thread-3148] 2016-06-01 12:00:33 [20160601155602e0c02031-1464796832222-NSRLM_10_SHARC:M2_1_RTL_OP,PCLN,PCLN,AVAIL,TWEB,06-01-2016 12:00:33,ASH1-RHSE-401,06-17-2016 00:00:00,06-19-2016 00:00:00 USD,en,N/A,N/A,0,122,115,2,1,121,27,0,0,27,0,0,0,0,0,0,0,0,1] [Thread-3152] 2016-06-01 12:00:33 [9e878a007e955fcc3b198f2095a34090-1464796830975-LS-M-A-2_1_MR_0,PCLN,MOBWEB,AVAIL,TWEB,06-01-2016 12:00:32,ASH1-RHSE-401,06-10-2016 00:00:00,06-12-2016 00:00:0 ,USD,en,N/A,N/A,957,1008,40,8,2,1006,10,0,10,0,0,10,10,10,0,0,14,1,6] [Thread-3156] 2016-06-01 12:00:33 [201606011547222632fd49-1464796832991-NSRLM_6_SHARC:I03_1_RTL,PCLN,PCLN,AVAIL,TWEB,06-01-2016 12:00:33,ASH1-RHSE-401,06-10-2016 00:00:00,06-12-2016 00:00:00,US ,en,N/A,N/A,0,5,4,1,0,5,2,0,0,2,0,0,0,0,0,0,0,0,1] [Thread-3156] 2016-06-01 12:00:33 [20160527205647949c671d-1464796832539-NSRLM_5_SHARC:D04_1_RTL,PCLN,PCLN,AVAIL,TWEB,06-01-2016 12:00:33,ASH1-RHSE-401,06-19-2016 00:00:00,06-20-2016 00:00:00,US ,en,N/A,N/A,0,34,30,1,0,34,6,0,0,6,0,0,0,0,0,0,0,0,1] [Thread-3152] 2016-06-01 12:00:33 [20160527205647949c671d-1464796832539-NSRLM_4_SHARC:D04_1_RTL,PCLN,PCLN,AVAIL,TWEB,06-01-2016 12:00:33,ASH1-RHSE-401,06-19-2016 00:00:00,06-20-2016 00:00:00,US ,en,N/A,N/A,0,50,44,1,1,49,17,0,0,17,0,0,0,0,0,0,0,0,1] [Thread-3153] 2016-06-01 12:00:33 [822efef6f8ae9b2087966af7326d263f_3_SHARC:H1-1_1_RTL,PCLN,PCLN,AVAIL,TWEB,06-01-2016 12:00:32,ASH1-RHSE-401,06-02-2016 00:00:00,06-03-2016 00:00:00,USD,en,N/A, /A,0,478,476,1,1,477,26,0,0,26,0,0,0,0,0,0,0,0,1] [Thread-3153] 2016-06-01 12:00:33 [20160601155602e0c02031-1464796832222-NSRLM_1_SHARC:M1-3_1_RTL,PCLN,PCLN,AVAIL,TWEB,06-01-2016 12:00:33,ASH1-RHSE-401,06-17-2016 00:00:00,06-19-2016 00:00:00,U D,en,N/A,N/A,0,9,6,0,0,9,2,0,0,2,0,0,0,0,0,0,0,0,0] [Thread-3153] 2016-06-01 12:00:33 [20160601155602e0c02031-1464796832222-NSRLM_1_SHARC:M1-6_1_RTL,PCLN,PCLN,AVAIL,TWEB,06-01-2016 12:00:33,ASH1-RHSE-401,06-17-2016 00:00:00,06-19-2016 00:00:00,U D,en,N/A,N/A,0,23,22,1,0,23,2,0,0,2,0,0,0,0,0,0,0,0,1] [Thread-3153] 2016-06-01 12:00:33 [dc332c7693d660eaf4c53afad02a824e_3_SHARC:X1_1_RTL_OP,PCLN,ANDNEG,AVAIL,TWEB,06-01-2016 12:00:33,ASH1-RHSE-401,06-01-2016 00:00:00,06-02-2016 00:00:00,USD,en,N A,N/A,0,15,11,0,1,14,6,0,0,6,0,0,0,0,0,0,0,0,0] [Thread-3153] 2016-06-01 12:00:33 [2016060115563226517f23-1464796833331-NSRLM_3_SHARC:S1_1_RTL_OP,PCLN,PCLN,AVAIL,TWEB,06-01-2016 12:00:33,ASH1-RHSE-401,06-17-2016 00:00:00,06-19-2016 00:00:00, SD,en,N/A,N/A,0,14,9,1,0,14,3,0,0,3,0,0,0,0,0,0,0,0,0] [Thread-3152] 2016-06-01 12:00:33 [2016060115563226517f23-1464796833331-NSRLM_4_SHARC:S1_1_RTL,PCLN,PCLN,AVAIL,TWEB,06-01-2016 12:00:33,ASH1-RHSE-401,06-17-2016 00:00:00,06-19-2016 00:00:00,USD en,N/A,N/A,0,64,60,0,1,63,1,0,0,1,0,0,0,0,0,0,0,0,0] [Thread-3153] 2016-06-01 12:00:33 [c080ff6460aa5d11aa92068ea704deb6_2_SHARC:K03_1_RTL_OP,PCLN,PCLN,AVAIL,TWEB,06-01-2016 12:00:33,ASH1-RHSE-401,07-01-2016 00:00:00,07-03-2016 00:00:00,USD,en,N/ ,N/A,0,96,90,1,1,95,11,0,0,11,0,0,0,0,0,0,0,0,0] [Thread-3152] 2016-06-01 12:00:33 [0ff279a5000001550c55f90df8170004-XML,HBC,HBC2ZW,AVAIL,TWEB,06-01-2016 12:00:33,ASH1-RHSE-401,06-04-2016 00:00:00,06-05-2016 00:00:00,USD,en,N/A,N/A,0,68,52,11 1,67,1,0,1,0,1,0,0,0,0,0,27,0,10] [Thread-3152] 2016-06-01 12:00:33 [2f9429678f9922c6d15f99848bc687f3_2_SHARC:I1_1_RTL_OP,PCLN,ANDNEG,AVAIL,TWEB,06-01-2016 12:00:33,ASH1-RHSE-401,08-16-2016 00:00:00,08-24-2016 00:00:00,USD,en,N A,N/A,0,28,24,0,0,28,5,0,0,5,0,0,0,0,0,0,0,0,0] [Thread-3157] 2016-06-01 12:00:33 [2016060116001905387014-1464796984883-NSRLM_2_SHARC:A03_1_CugCORE,PCLN,PCLN,AVAIL,CORE,06-01-2016 12:00:30,ASH1-RHSE-401,10-10-2016 00:00:00,10-14-2016 00:00:0 ,USD,en,N/A,N/A,3019,3069,45,4,1,3068,6,7,0,0,0,7,0,7,0,0,40,1,3]`; // Reset `lastIndex` if this regex is defined globally // regex.lastIndex = 0; let m; if ((m = regex.exec(str)) !== null) { // The result can be accessed through the `m`-variable. m.forEach((match, groupIndex) => { console.log(`Found match, group ${groupIndex}: ${match}`); }); }

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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions