Regular Expressions 101

Save & Share

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

/
/
g

Test String

Code Generator

Generated Code

$re = '/\"(?<my_field1>xyz-[^\"]*)\":\"(?<my_field2>[^\"]*)/'; $str = ' 2017-06-27 14:35:38.000 INFO [http-nio-0.0.0.0-19752-exec-4 - RequestResponseLoggerFilter] SessionID 2017-06-28-10:31:01-0855306 correlationID:bbacfa29-095d-49c0-b146-fe456h417ecbb681 "Request" : {"top":{"ref":"https://abc.com","adrum":"isAjax:true","content-length":"199","xyz-id":"123456","origin":"https://offline.xyz.com","xyz-authenticationprovider":"kbc","xyz-kbc-entry":"ipad","xyz-originaluri":"/kpi/abcf","via":"http/1.1 xyz.com","xyz-hyt-entrydomain":"mb","xyz-ipaddress":"117.00.109.103","xyz-originatorauthentication":"VUJTLdGhlbnRpY2F0aW9uTW5hbFVyaT0lMkZhcGklMkZ3bWElMkZjcmVkaXQtY2FyZC1wYXltZW50cyUyRnYxJTJGc2NoZWR1bGVkJTJGYWRkJlVCUy1SZXF1ZXN0QmFzZVVybD1odHRwcyU","x-forwarded-host":"offline.xyz.com","xyz-isuseraccessinganyaddressinternally":"false","x-forwarded-prefix":"/api","xyz-isuseraccessinginternally":"false","host":"offline.xyz.com","content-type":"application/json","xyz-hyt-hashregistrationid":"61fa7e9eb9afca3c09412a10fb02986d","accept-language":"en-us","xyz-authenticationlevel":"25","x-forwarded-proto":"https","dnt":"1","x-forwarded-for":"173.66.169.203","xyz-requestbaseurl":"https://offline.xyz.com/api","accept":"*/*","xyz-hyt-registrationid":"123456","x-forwarded-server":"148.112.147.17","singularityheader":"appId=7*ctrlguid=123456*acctguid=3f5d5ee2-41b3-4e59-ad10-de0b93044*ts=1498660534590*btid=2206*id=9497e8be-3275-417b-9893-30dbcca2d0*exitid=2*unresolvedexitid=164*cidfrom=148*etypeorder=CUSTOM*esubtype=CUSTOM*cidto=545","xyz-hyt-sessionid":"2017-06-28-10:31:01-085","xyz-isproxyuser":"false","xyz-isemployee":"false","xyz-hyt-entrypoint":"Mens","accept-encoding":"gzip,deflate","user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/603.2.5 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.5","xyz-iscallersecure":"true"},"correlationId":"bbddfa29-09fd-45c0-b136-fe417ecbb681"}'; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

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 PHP, please visit: http://php.net/manual/en/ref.pcre.php