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

r"
"
gm

Test String

Code Generator

Generated Code

#include <StringConstants.au3> ; to declare the Constants of StringRegExp #include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate Local $sRegex = "(?m)\n(\d{4}).*(?:\n\(.*)*\n\[(?: *|\d+-\d+-\d+)]" Local $sString = "" & @CRLF & _ "0047 Heptasilver nitrate octaoxide" & @CRLF & _ "[12258-22-9] Ag NO" & @CRLF & _ "7 11" & @CRLF & _ "(Ag O ) .AgNO" & @CRLF & _ "3 4 2 3" & @CRLF & _ "Alone, or Sulfides, or Nonmetals" & @CRLF & _ "The crystalline product produced by electrolytic oxidation" & @CRLF & _ "of silver nitrate (and possibly as formulated) detonates" & @CRLF & _ "feebly at 110°C. Mixtures with phosphorus and sulfur" & @CRLF & _ "explode on impact, hydrogen sulfide ignites on contact," & @CRLF & _ "and antimony trisulfide ignites when ground with the salt." & @CRLF & _ "Mellor, 1941, Vol. 3, 483–485" & @CRLF & _ "See other SILVER COMPOUNDS" & @CRLF & _ "See related METAL NITRATES" & @CRLF & _ "0048 Aluminium" & @CRLF & _ "[7429-90-5] Al" & @CRLF & _ "Al" & @CRLF & _ "HCS 1980, 135 (powder)" & @CRLF & _ "Finely divided aluminium powder or dust forms highly" & @CRLF & _ "explosive dispersions in air [1], and all aspects of pre-" & @CRLF & _ "vention of aluminium dust explosions are covered in 2" & @CRLF & _ "US National Fire Codes [2]. The effects on the ignition" & @CRLF & _ "properties of impurities introduced by recycled metal used" & @CRLF & _ "to prepare dust were studied [3]. Pyrophoricity is elimi-" & @CRLF & _ "nated by surface coating aluminium powder with poly-" & @CRLF & _ "styrene [4]. Explosion hazards involved in arc and flame" & @CRLF & _ "spraying of the powder were analyzed and discussed [5]," & @CRLF & _ "and the effect of surface oxide layers on flammability" & @CRLF & _ "was studied [6]. The causes of a severe explosion in" & @CRLF & _ "1983 in a plant producing fine aluminium powder were" & @CRLF & _ "analyzed, and improvements in safety practices discussed" & @CRLF & _ "[7]. A number of fires and explosions involving aluminiumdust arising from grinding, polishing, and buffing opera-" & @CRLF & _ "tions were discussed, and precautions detailed [8] [12]" & @CRLF & _ "[13]. Atomized and flake aluminium powders attain" & @CRLF & _ "See other METALS" & @CRLF & _ "See other REDUCANTS" & @CRLF & _ "0049 Aluminium-cobalt alloy (Raney cobalt alloy)" & @CRLF & _ "[37271-59-3] 50:50; [12043-56-0] Al Co; Al—Co" & @CRLF & _ "5" & @CRLF & _ "[73730-53-7] Al Co" & @CRLF & _ "2" & @CRLF & _ "Al Co" & @CRLF & _ "The finely powdered Raney cobalt alloy is a significant" & @CRLF & _ "dust explosion hazard." & @CRLF & _ "See DUST EXPLOSION INCIDENTS (reference 22)" & @CRLF & _ "0050 Aluminium–copper–zinc alloy" & @CRLF & _ "(Devarda’s alloy)" & @CRLF & _ "[8049-11-4] Al—Cu—Zn" & @CRLF & _ "Al Cu Zn" & @CRLF & _ "Silver nitrate: Ammonia, etc." & @CRLF & _ "See DEVARDA’S ALLOY" & @CRLF & _ "See other ALLOYS0051 Aluminium amalgam (Aluminium–" & @CRLF & _ "mercury alloy)" & @CRLF & _ "[12003-69-9] (1:1) Al—Hg" & @CRLF & _ "Al Hg" & @CRLF & _ "The amalgamated aluminium wool remaining from prepa-" & @CRLF & _ "ration of triphenylaluminium will rapidly oxidize and" & @CRLF & _ "become hot upon exposure to air. Careful disposal is nec-" & @CRLF & _ "essary [1]. Amalgamated aluminium foil may be pyro-" & @CRLF & _ "phoric and should be kept moist and used immediately [2]." & @CRLF & _ "1. Neely, T. A. et al., Org. Synth., 1965, 45, 109" & @CRLF & _ "2. Calder, A. et al., Org. Synth., 1975, 52, 78" & @CRLF & _ "See other ALLOYS" Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYGLOBALFULLMATCH) Local $aFullArray[0] For $i = 0 To UBound($aArray) -1 _ArrayConcatenate($aFullArray, $aArray[$i]) Next $aArray = $aFullArray ; Present the entire match result _ArrayDisplay($aArray, "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 AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm