Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
Sponsors
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
Processing...

Test String

Substitution
Processing...

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"""(sourceIPAddress)("":""[a-z]+)"; string substitution = @"""sourceIPAddressDNS$2"; string input = @"{""eventID"":""3e3f96e0-c68d-428e-ba18-cc57ebdc6bbe"",""awsRegion"":""us-east-1"",""eventVersion"":""1.05"",""responseElements"":null,""sourceIPAddress"":""autoscaling.amazonaws.com"",""requestParameters"":{""instancesSet"":{""items"":[{""instanceId"":""i-02b8cb7498ce8cbfb""},{""instanceId"":""i-07d9a98d8a331759c""}]},""filterSet"":{},""includeAllInstances"":true},""eventSource"":""ec2.amazonaws.com"",""userAgent"":""autoscaling.amazonaws.com"",""eventType"":""AwsApiCall"",""userIdentity"":{""type"":""AssumedRole"",""principalId"":""AROAJ6ODAVQ7WP3BHZK3K:AutoScaling"",""arn"":""arn:aws:sts::823260106468:assumed-role/AWSServiceRoleForAutoScaling/AutoScaling"",""accountId"":""823260106468"",""sessionContext"":{""sessionIssuer"":{""type"":""Role"",""principalId"":""AROAJ6ODAVQ7WP3BHZK3K"",""arn"":""arn:aws:iam::823260106468:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling"",""accountId"":""823260106468"",""userName"":""AWSServiceRoleForAutoScaling""},""webIdFederationData"":{},""attributes"":{""mfaAuthenticated"":""false"",""creationDate"":""2020-04-06T23:47:06Z""}},""invokedBy"":""autoscaling.amazonaws.com""},""requestID"":""a02802a3-3d7f-4a89-af5d-dde4c3bf3332"",""sourceIPAddress_geoip"":{""ip"":""autoscaling.amazonaws.com"",""location"":{""lat"":39.0481,""lon"":-77.4728},""continent_name"":""North America"",""country_name"":""United States"",""city_name"":""Ashburn"",""postal_code"":""20149""},""eventTime"":""2020-04-06T23:53:06Z"",""eventName"":""DescribeInstanceStatus"",""recipientAccountId"":""823260106468""} {""eventID"":""9ada7516-4680-47f5-8dea-c214472790b0"",""awsRegion"":""eu-west-1"",""eventVersion"":""1.05"",""responseElements"":null,""sourceIPAddress"":""autoscaling.amazonaws.com"",""requestParameters"":{""instances"":[],""loadBalancerName"":""um-ielb-dev-eu-euw1""},""eventSource"":""elasticloadbalancing.amazonaws.com"",""userAgent"":""autoscaling.amazonaws.com"",""eventType"":""AwsApiCall"",""userIdentity"":{""type"":""AssumedRole"",""principalId"":""AROAIHTUVAD5PEYEQN6BG:AutoScaling"",""arn"":""arn:aws:sts::631024868200:assumed-role/AWSServiceRoleForAutoScaling/AutoScaling"",""accountId"":""631024868200"",""accessKeyId"":""ASIAZF3ADLNUKCYLSHV2"",""sessionContext"":{""sessionIssuer"":{""type"":""Role"",""principalId"":""AROAIHTUVAD5PEYEQN6BG"",""arn"":""arn:aws:iam::631024868200:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling"",""accountId"":""631024868200"",""userName"":""AWSServiceRoleForAutoScaling""},""webIdFederationData"":{},""attributes"":{""mfaAuthenticated"":""false"",""creationDate"":""2020-04-06T23:34:29Z""}},""invokedBy"":""autoscaling.amazonaws.com""},""apiVersion"":""2012-06-01"",""requestID"":""2247127f-8e85-40e0-a7a2-ba498b2df0e6"",""sourceIPAddress_geoip"":{""ip"":""autoscaling.amazonaws.com"",""location"":{""lat"":39.0481,""lon"":-77.4728},""continent_name"":""North America"",""country_name"":""United States"",""city_name"":""Ashburn"",""postal_code"":""20149""},""eventTime"":""2020-04-06T23:48:28Z"",""eventName"":""DescribeInstanceHealth"",""recipientAccountId"":""631024868200""} {""eventID"":""e2286766-c504-4e9f-932a-e71f5bd35c60"",""awsRegion"":""ap-south-1"",""eventVersion"":""1.05"",""responseElements"":null,""sourceIPAddress"":""13.235.19.160"",""requestParameters"":{""encryptionContext"":{""aws:lambda:FunctionArn"":""arn:aws:lambda:ap-south-1:512088657713:function:cloudtrailtocoralogix-512088657713""},""encryptionAlgorithm"":""SYMMETRIC_DEFAULT""},""eventSource"":""kms.amazonaws.com"",""resources"":[{""accountId"":""512088657713"",""type"":""AWS::KMS::Key"",""ARN"":""arn:aws:kms:ap-south-1:512088657713:key/4222f8b2-329f-4882-b33e-8be3fc6e0ec3""}],""readOnly"":true,""userAgent"":""aws-internal/3 aws-sdk-java/1.11.728 Linux/4.14.165-103.209.amzn1.x86_64 OpenJDK_64-Bit_Server_VM/11.0.6+10-LTS java/11.0.6 vendor/Amazon.com_Inc."",""eventType"":""AwsApiCall"",""userIdentity"":{""type"":""AssumedRole"",""principalId"":""AROAXOOW4Z4YYSO4SS45M:cloudtrailtocoralogix-512088657713"",""arn"":""arn:aws:sts::512088657713:assumed-role/coralagixshipper-lambda-s3-readonly-role-512088657713/cloudtrailtocoralogix-512088657713"",""accountId"":""512088657713"",""accessKeyId"":""ASIAXOOW4Z4YVHC7ZB5V"",""sessionContext"":{""sessionIssuer"":{""type"":""Role"",""principalId"":""AROAXOOW4Z4YYSO4SS45M"",""arn"":""arn:aws:iam::512088657713:role/coralagixshipper-lambda-s3-readonly-role-512088657713"",""accountId"":""512088657713"",""userName"":""coralagixshipper-lambda-s3-readonly-role-512088657713""},""webIdFederationData"":{},""attributes"":{""mfaAuthenticated"":""false"",""creationDate"":""2020-04-06T21:31:50Z""}}},""requestID"":""2eaba276-74fd-4ce3-a1ec-5de092867a30"",""sourceIPAddress_geoip"":{""ip"":""13.235.19.160"",""location"":{""lat"":19.0748,""lon"":72.8856},""continent_name"":""Asia"",""country_name"":""India"",""city_name"":""Mumbai"",""postal_code"":""400070""},""eventTime"":""2020-04-06T22:09:22Z"",""eventName"":""Decrypt"",""recipientAccountId"":""512088657713""} {""eventID"":""a87aa588-15c7-4616-abd2-66a2ff7c56a9"",""awsRegion"":""us-east-1"",""eventVersion"":""1.05"",""responseElements"":null,""sourceIPAddress"":""52.76.143.145"",""requestParameters"":{""hostedZoneId"":""Z34GNXW2V0NNGS""},""eventSource"":""route53.amazonaws.com"",""userAgent"":""aws-sdk-go/1.13.32 (go1.12.1; linux; amd64)"",""eventType"":""AwsApiCall"",""userIdentity"":{""type"":""AssumedRole"",""principalId"":""AROAUAATSSJQGSUJH5JK7:i-00409e0426d2557c7"",""arn"":""arn:aws:sts::274918969952:assumed-role/masters.prod-apse1.hs-cricinfo.com/i-00409e0426d2557c7"",""accountId"":""274918969952"",""accessKeyId"":""ASIAUAATSSJQLWXEB3NU"",""sessionContext"":{""sessionIssuer"":{""type"":""Role"",""principalId"":""AROAUAATSSJQGSUJH5JK7"",""arn"":""arn:aws:iam::274918969952:role/masters.prod-apse1.hs-cricinfo.com"",""accountId"":""274918969952"",""userName"":""masters.prod-apse1.hs-cricinfo.com""},""webIdFederationData"":{},""attributes"":{""mfaAuthenticated"":""false"",""creationDate"":""2020-04-07T04:15:23Z""}}},""apiVersion"":""2013-04-01"",""requestID"":""0276937c-bbef-4416-a299-b979b87f35d8"",""sourceIPAddress_geoip"":{""ip"":""52.76.143.145"",""location"":{""lat"":1.2929,""lon"":103.8547},""continent_name"":""Asia"",""country_name"":""Singapore"",""city_name"":""Singapore"",""postal_code"":""18""},""eventTime"":""2020-04-07T06:50:36Z"",""eventName"":""ListResourceRecordSets"",""recipientAccountId"":""274918969952""} "; RegexOptions options = RegexOptions.Multiline; Regex regex = new Regex(pattern, options); string result = regex.Replace(input, substitution); } }

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 C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx