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

Substitution

Processing...

Code Generator

Generated Code

re = /^ [0-9]{4}\/[0-9]{2}\/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} \[\w+\] [0-9]+#[0-9]+:( \*[0-9]+)? (.*?)(( while( \\w+)+)?|, client: [^,]*|, server: [^,]*|, request: \"\w+ [^\"]* HTTP\/[^\"]+\"|, host: \"[^\"]*\"|, upstream: \"[^\"]*\"|, referrer: \"[^\"]*\"|, subrequest: \"[^\"]*\"|, ctx: \'[^\']*\')*$/m str = ' 2019/07/05 08:07:42 [info] 12759#12759: *32118 [lua] logging.lua:60: log(): req(f6c4b9e6-9efb-11e9-b199-005056a7ce13): Public inbound request (participant avatar): /rcvideo/v1/bridges/rnd01-t11-ndb01f1741f9416bc12ca506d77/meetings/rnd01-t11-ndb01f1741f9416bc12ca506d77_1562314057547!vi11-1/participants/3a9d_2571/profile-image/584x584?access_token=QU1TMDJQMDFQQVMwMHxBQUFXdm8yZ3hqY2NiZ0NvSXNReTFqT2FvZkFCTVhUNkRKdUNJdHBrazJ4dWJyWFl2akJqeVlUNmVQejJIVHRCRi1DdG5laEVYQnJSbVpXV0FRS3hHRVFwamlILW1haC1Ja1R4YnA4cWgzWlFZLWM0UWkzQm9iYmRWQUNKRnNtZ0NfWTRpeDJnMVFRak5zRkRtaFBWM0dId3dQUTdkZ1dnQU82bjBBM3ZsbWRlSlk4b215dUxjSHowSWR4NjRyR296b1NrTzBUOWduWFNzNUh0QllSQmNkbEl8Q25FdXJBfFlyRUFjVzY0MzdFOWZHeVotWE1Gb1F8QUE&allowSvg=true, client: 10.62.134.38, server: , request: "GET /rcvideo/v1/bridges/rnd01-t11-ndb01f1741f9416bc12ca506d77/meetings/rnd01-t11-ndb01f1741f9416bc12ca506d77_1562314057547!vi11-1/participants/3a9d_2571/profile-image/584x584?access_token=QU1TMDJQMDFQQVMwMHxBQUFXdm8yZ3hqY2NiZ0NvSXNReTFqT2FvZkFCTVhUNkRKdUNJdHBrazJ4dWJyWFl2akJqeVlUNmVQejJIVHRCRi1DdG5laEVYQnJSbVpXV0FRS3hHRVFwamlILW1haC1Ja1R4YnA4cWgzWlFZLWM0UWkzQm9iYmRWQUNKRnNtZ0NfWTRpeDJnMVFRak5zRkRtaFBWM0dId3dQUTdkZ1dnQU82bjBBM3ZsbWRlSlk4b215dUxjSHowSWR4NjRyR296b1NrTzBUOWduWFNzNUh0QllSQmNkbEl8Q25FdXJBfFlyRUFjVzY0MzdFOWZHeVotWE1Gb1F8QUE&allowSvg=true HTTP/1.1", host: "rnd01-t08-pwr01.lab.nordigy.ru", referrer: "https://vi11-1-v.lab.nordigy.ru/conf/on/644926345" 2019/07/05 08:07:42 [debug] 12759#12759: *32118 [lua] logging.lua:60: log(): req(f6c4b9e6-9efb-11e9-b199-005056a7ce13): Headers: RCAccountId: ; RCExtensionId: ; RCAppEndpointId: 4db17762-a1a0-404b-b118-1e8bdec1f900; RCRequestOrigin: Internal; 2019/07/05 08:07:42 [info] 12759#12759: *32118 [lua] logging.lua:60: log(): req(f6c4b9e6-9efb-11e9-b199-005056a7ce13): Making outbound subrequest to RCT/CHS: /rcvideo/v1/intapi/bridges/rnd01-t11-ndb01f1741f9416bc12ca506d77/meetings/rnd01-t11-ndb01f1741f9416bc12ca506d77_1562314057547!vi11-1/participants/3a9d_2571/profile-uri ..., client: 10.62.134.38, server: , request: "GET /rcvideo/v1/bridges/rnd01-t11-ndb01f1741f9416bc12ca506d77/meetings/rnd01-t11-ndb01f1741f9416bc12ca506d77_1562314057547!vi11-1/participants/3a9d_2571/profile-image/584x584?access_token=QU1TMDJQMDFQQVMwMHxBQUFXdm8yZ3hqY2NiZ0NvSXNReTFqT2FvZkFCTVhUNkRKdUNJdHBrazJ4dWJyWFl2akJqeVlUNmVQejJIVHRCRi1DdG5laEVYQnJSbVpXV0FRS3hHRVFwamlILW1haC1Ja1R4YnA4cWgzWlFZLWM0UWkzQm9iYmRWQUNKRnNtZ0NfWTRpeDJnMVFRak5zRkRtaFBWM0dId3dQUTdkZ1dnQU82bjBBM3ZsbWRlSlk4b215dUxjSHowSWR4NjRyR296b1NrTzBUOWduWFNzNUh0QllSQmNkbEl8Q25FdXJBfFlyRUFjVzY0MzdFOWZHeVotWE1Gb1F8QUE&allowSvg=true HTTP/1.1", host: "rnd01-t08-pwr01.lab.nordigy.ru", referrer: "https://vi11-1-v.lab.nordigy.ru/conf/on/644926345" 2019/07/05 08:07:42 [info] 12759#12759: *32118 [lua] logging.lua:60: log(): req(f6c4b9e6-9efb-11e9-b199-005056a7ce13): RCT/CHS: Status: 200 while sending to client, client: 10.62.134.38, server: , request: "GET /rcvideo/v1/bridges/rnd01-t11-ndb01f1741f9416bc12ca506d77/meetings/rnd01-t11-ndb01f1741f9416bc12ca506d77_1562314057547!vi11-1/participants/3a9d_2571/profile-image/584x584?access_token=QU1TMDJQMDFQQVMwMHxBQUFXdm8yZ3hqY2NiZ0NvSXNReTFqT2FvZkFCTVhUNkRKdUNJdHBrazJ4dWJyWFl2akJqeVlUNmVQejJIVHRCRi1DdG5laEVYQnJSbVpXV0FRS3hHRVFwamlILW1haC1Ja1R4YnA4cWgzWlFZLWM0UWkzQm9iYmRWQUNKRnNtZ0NfWTRpeDJnMVFRak5zRkRtaFBWM0dId3dQUTdkZ1dnQU82bjBBM3ZsbWRlSlk4b215dUxjSHowSWR4NjRyR296b1NrTzBUOWduWFNzNUh0QllSQmNkbEl8Q25FdXJBfFlyRUFjVzY0MzdFOWZHeVotWE1Gb1F8QUE&allowSvg=true HTTP/1.1", host: "rnd01-t08-pwr01.lab.nordigy.ru", referrer: "https://vi11-1-v.lab.nordigy.ru/conf/on/644926345" 2019/07/05 08:07:42 [info] 12759#12759: *32118 [lua] logging.lua:60: log(): req(f6c4b9e6-9efb-11e9-b199-005056a7ce13): Internal inbound request: /rcvideo/v1/intapi/uas/profile-image?accountId=&extensionId=&avatarUrl=https%3A%2F%2Fglipdevnet-rndtapams.s3.amazonaws.com%2Fweb%2Fcustomer_files%2F2383884%2Fmodified.jpg%3FExpires%3D2075494478%26AWSAccessKeyId%3DAKIAJO2PPFO3JEGRU4ZQ%26Signature%3DZvjWU0tKo6rLyN1ET2p6zBGQ8bI%253D&displayName=Joseph%20Tribbiani&type=regular&allow_svg=true&size=584x584&request_id=f6c4b9e6-9efb-11e9-b199-005056a7ce13 ..., client: 10.62.134.38, server: , request: "GET /rcvideo/v1/bridges/rnd01-t11-ndb01f1741f9416bc12ca506d77/meetings/rnd01-t11-ndb01f1741f9416bc12ca506d77_1562314057547!vi11-1/participants/3a9d_2571/profile-image/584x584?access_token=QU1TMDJQMDFQQVMwMHxBQUFXdm8yZ3hqY2NiZ0NvSXNReTFqT2FvZkFCTVhUNkRKdUNJdHBrazJ4dWJyWFl2akJqeVlUNmVQejJIVHRCRi1DdG5laEVYQnJSbVpXV0FRS3hHRVFwamlILW1haC1Ja1R4YnA4cWgzWlFZLWM0UWkzQm9iYmRWQUNKRnNtZ0NfWTRpeDJnMVFRak5zRkRtaFBWM0dId3dQUTdkZ1dnQU82bjBBM3ZsbWRlSlk4b215dUxjSHowSWR4NjRyR296b1NrTzBUOWduWFNzNUh0QllSQmNkbEl8Q25FdXJBfFlyRUFjVzY0MzdFOWZHeVotWE1Gb1F8QUE&allowSvg=true HTTP/1.1", host: "rnd01-t08-pwr01.lab.nordigy.ru", referrer: "https://vi11-1-v.lab.nordigy.ru/conf/on/644926345" 2019/07/05 08:07:42 [debug] 12759#12759: *32118 [lua] logging.lua:60: log(): req(f6c4b9e6-9efb-11e9-b199-005056a7ce13): Redirecting to /avatar/from-url (fallbacks: /avatar/from-nodejs;/errors/cannot-generate)... 2019/07/05 08:07:42 [debug] 12759#12759: *32118 [lua] set_by_lua:12: req(f6c4b9e6-9efb-11e9-b199-005056a7ce13): Fallback information: arg_fallback: "%2Favatar%2Ffrom-nodejs%3B%2Ferrors%2Fcannot-generate"; fallback_location: "/avatar/from-nodejs"; fallback_url: "/avatar/from-nodejs?fallback=%2Ferrors%2Fcannot%2Dgenerate&size=584x584&extension_id=&avatar_url=https%3A%2F%2Fglipdevnet-rndtapams.s3.amazonaws.com%2Fweb%2Fcustomer_files%2F2383884%2Fmodified.jpg%3FExpires%3D2075494478%26AWSAccessKeyId%3DAKIAJO2PPFO3JEGRU4ZQ%26Signature%3DZvjWU0tKo6rLyN1ET2p6zBGQ8bI%253D&request_id=f6c4b9e6-9efb-11e9-b199-005056a7ce13&account_id=&allow_svg=true&type=regular&display_name=Joseph%20Tribbiani&without_user_pic=false"; args_reduced_fallback: "size=584x584&extension_id=&avatar_url=https%3A%2F%2Fglipdevnet-rndtapams.s3.amazonaws.com%2Fweb%2Fcustomer_files%2F2383884%2Fmodified.jpg%3FExpires%3D2075494478%26AWSAccessKeyId%3DAKIAJO2PPFO3JEGRU4ZQ%26Signature%3DZvjWU0tKo6rLyN1ET2p6zBGQ8bI%253D&request_id=f6c4b9e6-9efb-11e9-b199-005056a7ce13&account_id=&allow_svg=true&type=regular&display_name=Joseph%20Tribbiani&without_user_pic=false"; args: "fallback=%2Favatar%2Ffrom-nodejs%3B%2Ferrors%2Fcannot-generate&size=584x584&extension_id=&avatar_url=https%3A%2F%2Fglipdevnet-rndtapams.s3.amazonaws.com%2Fweb%2Fcustomer_files%2F2383884%2Fmodified.jpg%3FExpires%3D2075494478%26AWSAccessKeyId%3DAKIAJO2PPFO3JEGRU4ZQ%26Signature%3DZvjWU0tKo6rLyN1ET2p6zBGQ8bI%253D&request_id=f6c4b9e6-9efb-11e9-b199-005056a7ce13&account_id=&allow_svg=true&type=regular&display_name=Joseph%20Tribbiani&without_user_pic=false" 2019/07/05 08:07:42 [info] 12759#12759: *32118 [lua] rewrite_by_lua(uas-base-location.conf:48):5: req(f6c4b9e6-9efb-11e9-b199-005056a7ce13): Making outbound subrequest to get avatar by direct url to "glipdevnet-rndtapams.s3.amazonaws.com": https://glipdevnet-rndtapams.s3.amazonaws.com/web/customer_files/2383884/modified.jpg?Expires=2075494478&AWSAccessKeyId=AKIAJO2PPFO3JEGRU4ZQ&Signature=ZvjWU0tKo6rLyN1ET2p6zBGQ8bI%3D ..., client: 10.62.134.38, server: , request: "GET /rcvideo/v1/bridges/rnd01-t11-ndb01f1741f9416bc12ca506d77/meetings/rnd01-t11-ndb01f1741f9416bc12ca506d77_1562314057547!vi11-1/participants/3a9d_2571/profile-image/584x584?access_token=QU1TMDJQMDFQQVMwMHxBQUFXdm8yZ3hqY2NiZ0NvSXNReTFqT2FvZkFCTVhUNkRKdUNJdHBrazJ4dWJyWFl2akJqeVlUNmVQejJIVHRCRi1DdG5laEVYQnJSbVpXV0FRS3hHRVFwamlILW1haC1Ja1R4YnA4cWgzWlFZLWM0UWkzQm9iYmRWQUNKRnNtZ0NfWTRpeDJnMVFRak5zRkRtaFBWM0dId3dQUTdkZ1dnQU82bjBBM3ZsbWRlSlk4b215dUxjSHowSWR4NjRyR296b1NrTzBUOWduWFNzNUh0QllSQmNkbEl8Q25FdXJBfFlyRUFjVzY0MzdFOWZHeVotWE1Gb1F8QUE&allowSvg=true HTTP/1.1", host: "rnd01-t08-pwr01.lab.nordigy.ru", referrer: "https://vi11-1-v.lab.nordigy.ru/conf/on/644926345" 2019/07/05 08:07:42 [debug] 12759#12759: *32118 [lua] rewrite_by_lua(uas-base-location.conf:48):6: req(f6c4b9e6-9efb-11e9-b199-005056a7ce13): Additional info: size: 584x584 2019/07/05 08:07:42 [debug] 12759#12759: *32118 [lua] log_by_lua(uas-base-location.conf:53):2: resp(f6c4b9e6-9efb-11e9-b199-005056a7ce13): Avatar fetched by url 2019/07/05 08:07:42 [info] 12759#12759: *32118 [lua] log_by_lua(uas-base-location.conf:53):3: resp(f6c4b9e6-9efb-11e9-b199-005056a7ce13): Upstream status: 200 while logging request, client: 10.62.134.38, server: , request: "GET /rcvideo/v1/bridges/rnd01-t11-ndb01f1741f9416bc12ca506d77/meetings/rnd01-t11-ndb01f1741f9416bc12ca506d77_1562314057547!vi11-1/participants/3a9d_2571/profile-image/584x584?access_token=QU1TMDJQMDFQQVMwMHxBQUFXdm8yZ3hqY2NiZ0NvSXNReTFqT2FvZkFCTVhUNkRKdUNJdHBrazJ4dWJyWFl2akJqeVlUNmVQejJIVHRCRi1DdG5laEVYQnJSbVpXV0FRS3hHRVFwamlILW1haC1Ja1R4YnA4cWgzWlFZLWM0UWkzQm9iYmRWQUNKRnNtZ0NfWTRpeDJnMVFRak5zRkRtaFBWM0dId3dQUTdkZ1dnQU82bjBBM3ZsbWRlSlk4b215dUxjSHowSWR4NjRyR296b1NrTzBUOWduWFNzNUh0QllSQmNkbEl8Q25FdXJBfFlyRUFjVzY0MzdFOWZHeVotWE1Gb1F8QUE&allowSvg=true HTTP/1.1", host: "rnd01-t08-pwr01.lab.nordigy.ru", referrer: "https://vi11-1-v.lab.nordigy.ru/conf/on/644926345" ' subst = '$2' result = str.gsub(re, subst) # Print the result of the substitution puts result

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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html