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

Code Generator

Generated Code

re = /^(003|004|007|010|011|012|014|015|016|017|018|021|024|025|029|033|036|037|040|041|047|060|062|063|064|065|066|069|070|074|075|076|077|078|079|080|081|082|083|084|085|088|089|091|092|093|094|095|096|097|098|099|100|101|102|104|105|107|108|111|113|114|341|117|119|120|121|122|124|125|126|127|128|129|130|131|132|133|134|136|138|139|140|142|143|144|145|146|149|157|159|163|169|173|174|177|180|183|184|188|189|190|191|194|196|197|208|212|213|217|218|222|224|233|237|241|243|246|249|250|253|254|259|260|265|266|268|269|270|271|272|273|274|276|278|279|280|281|283|285|286|288|289|290|292|293|296|298|299|300|301|306|307|309|310|313|315|318|319|320|321|322|323|324|325|326|329|330|331|332|335|336|340|342|343|348|349|350|352|354|355|359|360|362|363|364|365|366|367|368|370|371|373|374|376|377|378|379|380|381|382|383|384|387|389|390|391|393|394|395|396|397|399|402|403|404|406|408|412|422|456|464|473|477|479|487|488|492|495|505|545|600|604|610|611|612|613|623|626|630|633|634|637|643|652|653|654|655|707|712|739|741|743|745|746|747|748|751|752|753|754|755|756|757|001|000|016|017|018|021|024|025|029|033|036|037|040|041|047|060|062|063|064|065|066|069|070|074|075|076|077|078|079|080|081|082|083|084|085|088|089|091|092|093|094|095|096|097|098|099|100|101|102|104|105|107|108|111|113|114|341|117|119|120|121|122|124|125|126|127|128|129|130|131|132|133|134|136|138|139|140|142|143|144|145|146|149|157|159|163|169|173|174|177|180|183|184|188|189|190|191|194|196|197|208|212|213|217|218|222|224|233|237|241|243|246|249|250|253|254|259|260|265|266|268|269|270|271|272|273|274|276|278|279|280|281|283|285|286|288|289|290|292|293|296|298|299|300|301|306|307|309|310|313|315|318|319|320|321|322|323|324|325|326|329|330|331|332|335|336|340|342|343|348|349|350|352|354|355|359|360|362|363|364|365|366|367|368|370|371|373|374|376|377|378|379|380|381|382|383|384|387|389|390|391|393|394|395|396|397|399|402|403|404|406|408|412|422|456|464|473|477|479|487|488|492|495|505|545|600|604|610|611|612|613|623|626|630|633|634|637|643|652|653|654|655|707|712|739|741|743|745|746|747|748|751|752|753|754|755|756|757|001|000).{4}0.{45}(\d{4}).(\d{12})\w?.{72}(\d{8})/m str = '23700000 207366109000196000000000000000716060263280000000001279 FACELL COMERCIO DE CELULARES EBRADESCO S/A 20306202106483600041705001600 71606 ' # 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