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

use strict; my $str = 'https 2021-12-28T08:45:46.363601Z app/k8s-internaltelioalb-0189d12367/7b3deb885c66a05c 10.50.8.89:59718 10.50.16.243:3000 0.000 0.702 -1 502 - 492 272 "POST https://api-internal.prd.telio.me:443/internal/oms/graphql HTTP/1.1" "axios/0.21.1" ECDHE-RSA-AES128-GCM-SHA256 TLSv1.2 arn:aws:elasticloadbalancing:ap-southeast-1:305671018540:targetgroup/k8s-telio-omsservi-0d37efa96a/62501827cfb001cc "Root=1-61caceb9-7c362e4c422488481a886f20" "api-internal.prd.telio.me" "arn:aws:acm:ap-southeast-1:305671018540:certificate/1389500b-1e0f-4bb9-bfee-2356cf20f40d" 3 2021-12-28T08:45:45.658000Z "forward" "-" "-" "10.50.16.243:3000" "-" "-" "-" https 2021-12-28T08:46:08.788818Z app/k8s-internaltelioalb-0189d12367/7b3deb885c66a05c 10.50.8.77:46086 10.50.16.243:3000 0.000 3.849 -1 502 - 492 272 "GET https://api-internal.prd.telio.me:443/internal/oms/graphql?query=query%7B%0A++++++++++warehouseByCustomer(%0A++++++++++++verticalId:+%22null%22,%0A++++++++++++customerId:+%2238311%22,%0A++++++++++++addressId:+109138,%0A++++++++++++warId:+119101103,%0A++++++++++)%7B%0A++++++++++++id,%0A++++++++++++storeId,%0A++++++++++++name%0A++++++++%7D%7D HTTP/1.1" "axios/0.19.2" ECDHE-RSA-AES128-GCM-SHA256 TLSv1.2 arn:aws:elasticloadbalancing:ap-southeast-1:305671018540:targetgroup/k8s-telio-omsservi-0d37efa96a/62501827cfb001cc "Root=1-61cacecc-1a87e41c30f7191a28b89096" "api-internal.prd.telio.me" "session-reused" 3 2021-12-28T08:46:04.939000Z "forward" "-" "-" "10.50.16.243:3000" "-" "-" "-"'; my $regex = qr/^(?P<alb_type>(https?|h2|wss?))\s*(?P<alb_timestamp>[^\s]+)\s*(?P<alb_elb>[^\s]+)\s*(?P<alb_client_addr>[^:]+):\s*(?P<alb_client_port>[^\s]+)\s*(?P<alb_target_addr>[^:]+):\s*(?P<alb_target_port>[^\s]+)\s*\s*(?P<alb_request_processing_time>[^\s]+)\s*(?P<alb_target_processing_time>[^\s]+)\s*(?P<alb_response_processing_time>[^\s]+)\s*(?P<alb_elb_status_code>[^\s]+)\s*(?P<alb_target_status_code>[^\s]+)\s*(?P<alb_received_bytes>[^\s]+)\s*(?P<alb_sent_bytes>[^\s]+)\s*"(?P<alb_request>.*?)"\s+"(?P<alb_user_agent>[^\"]+)"\s*(?P<alb_ssl_cipher>[^\s]+)\s*(?P<alb_ssl_protocol>[^\s]+)\s*(?P<alb_target_group_arn>[^\s]+)\s*"(?P<alb_trace_id>[^\"]+)"\s*"(?P<alb_domain_name>[a-zA-Z0-9\.\-:]+)"\s*"(?P<alb_chosen_cert_arn>[^\"]+)"\s*(?P<alb_matched_rule_priority>[^\s]+)\s*(?P<alb_request_creation_time>[^\s]+)\s*\s*"(?P<alb_actions_executed>[^\s]+)"\s*"(?P<alb_redirect_url>[^\s]+)"\s*"(?P<alb_error_reason>[^\"]+)"\s*"?(?P<alb_target_port_list>[0-9 :\.-]+)"?\s*"?(?P<alb_target_status_code_list>[0-9 -]+)"?/mp; if ( $str =~ /$regex/g ) { print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n"; # print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n"; # print "Capture Group 2 is $2 ... and so on\n"; } # ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p' # Named capture groups can be called via $+{name}

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 Perl, please visit: http://perldoc.perl.org/perlre.html