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"
"
gm

Test String

Code Generator

Generated Code

re = /(?P<type>SLA)(?:::)(?P<sa>[0-9]{4,7}|(?:_))?(?:::)(?P<cid>[a-zA-Z-0-9-\/._]{8,}|(?:_))?(?:::)(?P<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|(?:_))?(?:::)(?P<desc>[\w#()\/-]*)/m str = 'SLA::3223453::801-4259::10.224.0.88::PIONEERLAND_DASSEL SLA::3223482::_::_::PIONEERLAND_RAYMOND UNI::3238811::ROCHESTER_COMMUNITY_COLLEGE SLA::_::_::10.224.0.88::PIONEERLAND_WILLMAR_DC SLA::3211691::A1Q0041C::_::TMOBILE_511_PARK_AVE SLA::3206176::EEVC/011439//2636/EPL::10.252.51.50::CHARTER_BANK SLA::3206176::_::10.252.51.50::CHARTER_BANK SLA::3223621::70.VLXP.024011..CBCL..::_::GOEBEL_FIXTURES_COMPANY SLA::3178253::KRE1/50393/MPT/CTTNMNTMOB1::10.224.0.88::TMOBILE_COTTON ACCESS::DSLAM_TEST SLA::3265812::L2XN/77798/MPT/LRTOMNARPF::10.224.0.159::CCI_ARROWHEAD_PROMOTION SLA::3152953::180-361-0266::10.252.51.101::HORMEL_BLOOMING_PRAIRIE SLA::3137605::GEYX/065858::10.252.2.203::ZAYO_VZW_KIMBALL SLA::3171637::88/INFR/102977//DCE/::10.252.2.25::BNC_BANK SLA::3182788::150-368-0293::10.252.51.36::NORTHFIELD-HOSPITAL SLA::3221907::EVENT_41767_PEARL_LAKE_LIT::10.224.0.166::VZW_PEARLLAKE SLA::_::_::_::VZW_GP_RED_WING_WEST SLA::3227386::16-KFLA-01156--NVP::_::ZAYO_DULUTH_GROUP' # 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