Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
Sponsors
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
Processing...

Test String

Code Generator

Generated Code

import re regex = re.compile(r"Fig[ures]+\sLege[nds]+?:?$\s*((?:(?!\n\n)\n?[^\n]+)*)", flags=re.IGNORECASE | re.MULTILINE) test_str = ("Figure legends\n\n" "Fig. 1 Time course of batch culture with and without additional acetate (working volume, 300 ml). TY medium without additional acetate (A0, a); 2 g/L acetate (A2, b) was supplied as co-carbon source; 4 g/L acetate (A4, c) was supplied as co-carbon source; 6 g/L acetate (A6, d) was supplied as co-carbon source. Symbols: open squares, glucose concentration in broth; open triangles, acetate concentration in broth; closed circles, butanol concentration in broth; closed triangles, acetone concentration in broth; Dashed line, pH of batch culture.\n\n" "Fig. 2 Mass spectra of butanol and acetone by GC-MS analysis. (a) 12C4-butanol solution as standard substance. (b) Mass spectra of butanol in culture broth of the N1-4 strain with 12C6-glucose and [1, 2-13C2] acetate for 24 h. Peak 1, 2 and 3, indicated by arrows, were derived from three type of butanol: 12C4-butanol, 13C2-butanol in which two out of four carbons were replaced by 13C-atom, and 13C4-butanol, respectively. (c) 12C3-acetone solution as standard substance. (d) Mass spectra of acetone in culture broth of the N1-4 strain with 12C6-glucose and [1, 2-13C2] acetate for 24 h. Peaks 4, 5, 6 and 7, indicated by arrows, were derived from four type of acetone: 12C3-acetone, 13C1-acetone in which one out of three carbons was replaced by 13C-atom, 13C2-acetone in which two out of three carbons were replaced by 13C-atom and 13C3-acetone, respectively. \n\n" "Fig. 3 Metabolic pathways of fractional 13C-labeling of intermediate metabolites resulting from [1,2-13C2] acetate input by using N1-4 strain. Acetone and butanol molecules composed of different 12C- and 13C-atoms indicate the respective percentages (%) by GC-MS analysis. Each culture (12C6-glucose, 50 g/L; [1,2-13C2] acetate, 4 g/L; working volume, 10 ml) was performed three times, and the average was represented as means ± standard deviation. Labeled 13C-atoms, closed circles; 12C-atoms, open circles; consumed carbon sources concentrations, in boxes and red words; products concentrations, green words. Left side presented data at 9 h (acidogenesis); righ side presented data at 24 h (solventogenesis). Enymes are abbreviated as follows: phosphotransacetylase (PTA); acetate kinase (AK); thiolase (THL); β-hydroxybutyryl dehydrogenase (BHBD); crotonase (CRO); butyryl-CoA dehydrogenase (BCD); CoA transferase (CoAT); acetoacetate decarboxylase (ADC); butyrate kinase (BK); phophotransbutyrylase (PTB); aldehyde/alcohol dehydrogenase (AAD); butanol dehydrogenase I (BDHA); butanol dehydrogenase II (BDHB). Putative approaches for acetate uptake") match = regex.search(test_str) if match: print(f"Match was found at {match.start()}-{match.end()}: {match.group()}") for group_num, group in enumerate(match.groups(), start=1): print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")

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 Python, please visit: https://docs.python.org/3/library/re.html