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 the latest version of the regex crate in your Cargo.toml extern crate regex; use regex::Regex; fn main() { let regex = Regex::new(r"(?m)\n(\d{4}).*(?:\n\(.*)*\n\[(?: *|\d+-\d+-\d+)]").unwrap(); let string = " 0047 Heptasilver nitrate octaoxide [12258-22-9] Ag NO 7 11 (Ag O ) .AgNO 3 4 2 3 Alone, or Sulfides, or Nonmetals The crystalline product produced by electrolytic oxidation of silver nitrate (and possibly as formulated) detonates feebly at 110°C. Mixtures with phosphorus and sulfur explode on impact, hydrogen sulfide ignites on contact, and antimony trisulfide ignites when ground with the salt. Mellor, 1941, Vol. 3, 483–485 See other SILVER COMPOUNDS See related METAL NITRATES 0048 Aluminium [7429-90-5] Al Al HCS 1980, 135 (powder) Finely divided aluminium powder or dust forms highly explosive dispersions in air [1], and all aspects of pre- vention of aluminium dust explosions are covered in 2 US National Fire Codes [2]. The effects on the ignition properties of impurities introduced by recycled metal used to prepare dust were studied [3]. Pyrophoricity is elimi- nated by surface coating aluminium powder with poly- styrene [4]. Explosion hazards involved in arc and flame spraying of the powder were analyzed and discussed [5], and the effect of surface oxide layers on flammability was studied [6]. The causes of a severe explosion in 1983 in a plant producing fine aluminium powder were analyzed, and improvements in safety practices discussed [7]. A number of fires and explosions involving aluminiumdust arising from grinding, polishing, and buffing opera- tions were discussed, and precautions detailed [8] [12] [13]. Atomized and flake aluminium powders attain See other METALS See other REDUCANTS 0049 Aluminium-cobalt alloy (Raney cobalt alloy) [37271-59-3] 50:50; [12043-56-0] Al Co; Al—Co 5 [73730-53-7] Al Co 2 Al Co The finely powdered Raney cobalt alloy is a significant dust explosion hazard. See DUST EXPLOSION INCIDENTS (reference 22) 0050 Aluminium–copper–zinc alloy (Devarda’s alloy) [8049-11-4] Al—Cu—Zn Al Cu Zn Silver nitrate: Ammonia, etc. See DEVARDA’S ALLOY See other ALLOYS0051 Aluminium amalgam (Aluminium– mercury alloy) [12003-69-9] (1:1) Al—Hg Al Hg The amalgamated aluminium wool remaining from prepa- ration of triphenylaluminium will rapidly oxidize and become hot upon exposure to air. Careful disposal is nec- essary [1]. Amalgamated aluminium foil may be pyro- phoric and should be kept moist and used immediately [2]. 1. Neely, T. A. et al., Org. Synth., 1965, 45, 109 2. Calder, A. et al., Org. Synth., 1975, 52, 78 See other ALLOYS"; // result will be an iterator over tuples containing the start and end indices for each match in the string let result = regex.captures_iter(string); for mat in result { println!("{:?}", mat); } }

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 Rust, please visit: https://docs.rs/regex/latest/regex/