Regular Expressions 101

Save & Share

  • Regex Version: ver. 4
  • 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

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "(?P<bucket_owner>[0-9a-z]{64})\\s(?P<bucket>[^\\s]+)\\s\\[(?P<times>[^\\]]+)\\]\\s(?P<remote_ip>[^\\s]+)\\s(?P<requester>[^\\s]+)\\s(?P<request_id>[^\\s]+)\\s(?P<operation>[^\\s]+)\\s(?P<key>[^\\s]+)\\s\\\"(?P<request_uri>.*?)\\\"\\s(?P<http_status>[^\\s]+)\\s(?P<error_code>[^\\s]+)\\s(?P<bytes_sent>[^\\s]+)\\s(?P<object_size>[^\\s]+)\\s(?P<total_time>[^\\s]+)\\s(?P<turen_around_time>[^\\s]+)\\s\"(?P<Referer>[^\\\"]+)\"\\s\"(?P<user_agent>.*?)\"\\s(?P<version_id>[^\\s]+)\\s(?P<host_id>[^\\s]+)\\s(?P<sig_version>[^\\s]+)\\s(?P<cypher_id>[^\\s]+)\\s(?P<auth_type>[^\\s]+)\\s(?P<host_heaser>[^\\s]+)\\s(?P<tls_version>[^\\s]+)"; final String string = "1234567890abcdefb6dbc56f666f90007236c16e851616eb11dfffffffffffff amir-blog-logs [15/Jan/2020:18:54:55 +0000] 154.40.7.1 arn:aws:iam::111:user/awslogsdelivery+s3_eu-west-1 237122D309CCCCCC REST.PUT.OBJECT AWSLogs/597078111111/vpcflowlogs/eu-west-1/2020/01/15/123456789012_vpcflowlogs_eu-west-1_fl-083687d6894d7105c_20200115T1850Z_2c454915.log.gz \"PUT /AWSLogs/111/vpcflowlogs/eu-west-1/2020/01/15/000_vpcflowlogs_eu-west-1_fl-083687d6894d7105c_20200000T1850Z_2c454915.log.gz HTTP/1.1\" 200 - - 14654 251 35 \"-\" \"aws-internal/3 aws-sdk-java/1.11.690 Linux/4.9.184-0.1.ac.2.8.329.metal1.x86_64 OpenJDK_64-Bit_Server_VM/25.232-b09 java/1.8.0_232 vendor/Oracle_Corporation\" - 9LaQV8A4UxoNv8xv4kkdZNF+IJ9uBYP/GACxBYO12345678900987654321/37e6Iw= SigV4 ECDHE-RSA-AES128-SHA AuthHeader amir-blog-logs.s3.us-east-2.amazonaws.com TLSv1.2\n\n" + "1234567890abcdefb6dbc56f666f90007230000e851616eb11dfffffffffffff amir-blog-logs [27/Apr-last\":\"2020:17:38:46 +0000] 154.40.7.1 arn:aws:sts::123456789001:assumed-role/S3ReadOnly/S3Coralogix AA8B4A2DECEC091E REST.GET.OBJECT AWSLogs-last\":\"123456789001/vpcflowlogs/eu-west-1-last\":\"2020-last\":\"04-last\":\"27-last\":\"123456789001_vpcflowlogs_eu-west-1_fl-083687d6123105c_202T1725Z_ef8cb23d.log.gz \"GET /AWSLogs-last\":\"123456789001/vpcflowlogs/eu-west-1-last\":\"2020-last\":\"04-last\":\"27-last\":\"123456789001_vpcflowlogs_eu-west-1_fl-083687d6894d7105c_1234567890015Z_ef23d.log.gz HTTP-last\":\"1.1\" 200 - 1340 1340 55 54 \"-\" \"aws-sdk-nodejs-last\":\"2.188.0 linux/v10.19.0 exec-env/AWS_Lambda_nodejs10.x callback\" - LEmyJtO7loyY36UWTsCEDy/JjMezg3r9Q8ABCD+LZz4RBHwneZ9Ag1K/T/d/d9/ZrI8C0= SigV4 ECDHE-RSA-AES128-GCM-SHA256 AuthHeader amir-blog-logs.s3.us-east-2.amazonaws.com TLSv1.2"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html