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
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
Processing...

Test String

Substitution
Processing...

Code Generator

Generated Code

use strict; my $str = '{ "2597401": [ { "jobID": "2597401", "account": "TG-CCR120014", "user": "charngda", "pkgT": { "pgi/7.2- 5": { "libA": [ "libpgc.so" ], "flavor": [ "default" ] } }, "startEpoch": "1338497979", "runTime": "1022", "execType": "user:binary", "exec": "ft.D.64", "numNodes": "4", "sha1": "5a79879235aa31b6a46e73b43879428e2a175db5", "execEpoch": 1336766742, "execModify": "Fri May 11 15:05:42 2012", "startTime": "Thu May 31 15:59:39 2012", "numCores": "64", "sizeT": { "bss": "1881400168", "text": "239574", "data": "22504" } }, { "jobID": "2597401", "account": "TG-CCR120014", "user": "charngda", "pkgT": { "pgi/7.2-5": { "libA": [ "libpgc.so" ], "flavor": [ "default" ] } }, "startEpoch": "1338497946", "runTime": "33", "execType": "user:binary", "exec": "cg.C.64", "numNodes": "4", "sha1": "caf415e011e28b7e4e5b050fb61cbf71a62a9789", "execEpoch": 1336766735, "execModify": "Fri May 11 15:05:35 2012", "startTime": "Thu May 31 15:59:06 2012", "numCores": "64", "sizeT": { "bss": "29630984", "text": "225749", "data": "20360" } }, { "jobID": "2597401", "account": "TG-CCR120014", "user": "charngda", "pkgT": { "pgi/7.2-5": { "libA": [ "libpgc.so" ], "flavor": [ "default" ] } }, "startEpoch": "1338500447", "runTime": "145", "execType": "user:binary", "exec": "mg.D.64", "numNodes": "4", "sha1": "173de32e1514ad097b1c051ec49c4eb240f2001f", "execEpoch": 1336766756, "execModify": "Fri May 11 15:05:56 2012", "startTime": "Thu May 31 16:40:47 2012", "numCores": "64", "sizeT": { "bss": "456954120", "text": "426186", "data": "22184" } }, { "jobID": "2597401", "account": "TG-CCR120014", "user": "charngda", "pkgT": { "pgi/7.2-5": { "libA": [ "libpgc.so" ], "flavor": [ "default" ] } }, "startEpoch": "1338499002", "runTime": "1444", "execType": "user:binary", "exec": "lu.D.64", "numNodes": "4", "sha1": "c6dc16d25c2f23d2a3321d4feed16ab7e10c2cc1", "execEpoch": 1336766748, "execModify": "Fri May 11 15:05:48 2012", "startTime": "Thu May 31 16:16:42 2012", "numCores": "64", "sizeT": { "bss": "199850984", "text": "474218", "data": "27064" } } ] }'; my $regex = qr/(?:(?=(?&V_Obj)){(?=(?:(?&V_KeyVal)(?&Sep_Obj))*?\s*("jobID"\s*:\s*(?&V_Value)))(?=(?:(?&V_KeyVal)(?&Sep_Obj))*?\s*("exec"\s*:\s*(?&V_Value)))(?:(?&V_KeyVal)(?&Sep_Obj))+})(?(DEFINE)(?<Sep_Ary>\s*(?:,(?!\s*[}\]])|(?=\])))(?<Sep_Obj>\s*(?:,(?!\s*[}\]])|(?=})))(?<Str>(?>"[^\\"]*(?:\\[\s\S][^\\"]*)*"))(?<Numb>(?>[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?|(?:[eE][+-]?\d+)))(?<V_KeyVal>(?>\s*(?&Str)\s*:\s*(?&V_Value)\s*))(?<V_Value>(?>(?&Numb)|(?>true|false|null)|(?&Str)|(?&V_Obj)|(?&V_Ary)))(?<V_Ary>\[(?>\s*(?&V_Value)(?&Sep_Ary))*\s*\])(?<V_Obj>{(?>(?&V_KeyVal)(?&Sep_Obj))*\s*}))/mp; my $subst = '{ $1, $2 }'; my $result = $str =~ s/$regex/$subst/rg; print "The result of the substitution is' $result\n";

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