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"EGA-(?:(?!New=).)+(New=[:\d\/ ]+)") test_str = ("structure(list(flight_history_id = c(280604281L, 280316415L, \n" "280315758L, 280316495L, 280303866L, 280303866L, 280271465L, 280271465L, \n" "280271465L, 280271465L), date_time_recorded = structure(c(10L, \n" "4L, 3L, 2L, 7L, 1L, 9L, 8L, 6L, 5L), .Label = c(\"2012-11-12 05:50:23.547-08\", \n" "\"2012-11-12 15:38:10.099-08\", \"2012-11-12 16:10:06.968-08\", \"2012-11-12 17:25:08.814-08\", \n" "\"2012-11-12 17:58:14.268-08\", \"2012-11-13 05:16:41.01-08\", \"2012-11-13 06:51:45.831-08\", \n" "\"2012-11-13 07:38:19.593-08\", \"2012-11-13 07:54:22.588-08\", \"2012-11-13 17:55:58.673-08\"\n" "), class = \"factor\"), event = structure(c(1L, 2L, 2L, 2L, 2L, \n" "2L, 2L, 2L, 2L, 2L), .Label = c(\"Arrival Estimation\", \"Time Adjustment\"\n" "), class = \"factor\"), data_updated = structure(c(3L, 8L, 7L, \n" "4L, 2L, 5L, 1L, 10L, 9L, 6L), .Label = c(\"AGD- New=11/13/12 10:22, EGA- Old=11/13/12 11:20 New=11/13/12 11:09\", \n" "\"AGD- Old=11/13/12 07:40 New=11/13/12 07:38, EGA- Old=11/13/12 10:25 New=11/13/12 10:18\", \n" "\"EGA- Based on Distance and Airspeed\", \"EGD- New=11/13/12 06:35, DGATE- New=A1, EGA- New=11/13/12 07:15\", \n" "\"EGD- New=11/13/12 07:45, DGATE- New=11, EGA- New=11/13/12 10:25, AGATE- New=A1\", \n" "\"EGD- New=11/13/12 08:55, EGA- New=11/13/12 09:45, AGATE- New=A1\", \n" "\"EGD- New=11/13/12 19:05, DGATE- New=A7, EGA- New=11/13/12 20:50, AGATE- New=C5\", \n" "\"EGD- New=11/13/12 20:20, DGATE- New=A1, EGA- New=11/13/12 21:00\", \n" "\"EGD- Old=11/13/12 08:55 New=11/13/12 10:05, EGA- Old=11/13/12 09:45 New=11/13/12 10:55\", \n" "\"EGD- Old=11/13/12 10:05 New=11/13/12 10:30, EGA- Old=11/13/12 10:55 New=11/13/12 11:20\"\n" "), class = \"factor\")), .Names = c(\"flight_history_id\", \"date_time_recorded\", \n" "\"event\", \"data_updated\"), row.names = c(862L, 5514L, 5527L, 5539L, \n" "5545L, 5558L, 5564L, 5566L, 5570L, 5572L), class = \"data.frame\")") matches = regex.finditer(test_str) for match_num, match in enumerate(matches, start=1): print(f"Match {match_num} 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