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
No Match

r"
"
gms

Test String

Code Generator

Generated Code

re = /(?P<bar>\+[+\-=]+\+)(?P<headline>.*?)(\+[+\-=]+\+)(?P<body>.*?)(\+[+\-=]+\+)/m str = '+----+--------------------------------------+-------------+----------+--------+--------+--------------------+------------------+-------+-----------------+------------------------------+------------+-----------+--------------+------------+---------------------------------------------+---------------------+---------+ | No | ID | Name | VNFM | VIM | Tenant | VNF Package | Flavor | Level | Aspect | VNF Status | Job Status | Scale Opt | Scale Mode | Scale Unit | Workflow | Created At | Visible | +----+--------------------------------------+-------------+----------+--------+--------+--------------------+------------------+-------+-----------------+------------------------------+------------+-----------+--------------+------------+---------------------------------------------+---------------------+---------+ | 0 | 0960ad53-bf7a-4c56-b980-cfa05a33fe71 | vzw_u13_cp3 | NSA_VNFM | simvim | vran | vzw_u13_cp3_i12i00 | VRAN-FLAVOR | 0 | SA_CPC=0 | vnf.instance.instantiate.end | COMPLETED | Enabled | Auto Scale | VDU | workflow_etsi-com-vnf_nfvo_direct_1_0_0.jar | 2021-01-12 04:35:51 | true | | 1 | 33434187-2d82-48bd-9fd0-c67f2a8c9c87 | vzw_usm14 | NSA_VNFM | simvim | vsm | vzw21a_usm14 | VEMS-FLAVOR-TINY | 0 | AS_CF=0,AS_PS=0 | vnf.instance.instantiate.end | COMPLETED | Disabled | Manual Scale | VDU | workflow_etsi-com-vnf_nfvo_direct_1_0_0.jar | 2020-12-24 14:22:03 | true | | 2 | 94b68ddb-06e6-45ae-a7dc-bf9204f61aa3 | vzw_usm12 | NSA_VNFM | simvim | vsm | vzw21a_usm12 | VEMS-FLAVOR-TINY | 0 | AS_CF=0,AS_PS=0 | vnf.instance.instantiate.end | COMPLETED | Disabled | Manual Scale | VDU | workflow_etsi-com-vnf_nfvo_direct_1_0_0.jar | 2020-12-24 13:15:55 | true | | 3 | b60fdfff-c8d7-4656-bd77-d4621c1efbe5 | vzw_usm13 | NSA_VNFM | simvim | vsm | vzw21a_usm13 | VEMS-FLAVOR-TINY | 0 | AS_CF=0,AS_PS=0 | vnf.instance.instantiate.end | COMPLETED | Disabled | Manual Scale | VDU | workflow_etsi-com-vnf_nfvo_direct_1_0_0.jar | 2020-12-24 13:51:24 | true | | 4 | c3de1762-57fb-4c0f-875e-e3b960629663 | vzw_u13_up3 | NSA_VNFM | simvim | vran | vzw_u13_up3_i12i00 | VRAN-FLAVOR | 0 | SA_UPC=0 | vnf.instance.instantiate.end | COMPLETED | Enabled | Auto Scale | VDU | workflow_etsi-com-vnf_nfvo_direct_1_0_0.jar | 2021-01-12 04:26:30 | true | +----+--------------------------------------+-------------+----------+--------+--------+--------------------+------------------+-------+-----------------+------------------------------+------------+-----------+--------------+------------+---------------------------------------------+---------------------+---------+ item count : 5 [vnf-list] OK' # Print the match result str.scan(re) do |match| puts match.to_s end

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