Save & Share

  • Current Version: 2
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to 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
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
Processing...

Test String

Code Generator

Generated Code

import re regex = re.compile(r"a") test_str = ("STAT 545 REGULAR EXPRESSION TEST BED\n" "------------------------------------\n\n" "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" "0123456789 +-.,!@#$%^&*();\\/|<>\"'\n" "12345 -98.7 3.141 .6180 9,000 +42\n\n" "Twas brillig, and the slithy toves\n" " Did gyre and gimble in the wabe;\n" "All mimsy were the borogoves,\n" " And the mome raths outgrabe.\n\n" "3317 Route 202 \n" "Long Branch, NJ 07740\n\n" "9303 Route 1 \n" "Sun City, AZ 85351\n\n\n" "CHALLENGES\n" "-------------------------------------\n\n" "RULES\n" "1. Match ONLY the target elements (check top of document as well!)\n" "2. Must be a separate match for each discrete element\n" "3. THERE ARE CANDY PRIZES\n\n" "1. DNA:\n" "TCCGTATCAAGATCCTCTTAATAAGCCCCCGTCACTGTTGGTTGTAGAGCCCAGGACGGGTTGGCCAGATGTGCGACTATATCGCTTAGTGGCTCTTGGGCC\n\n" "GATAGCTTCTTACCGGTGCGCCTCCGTACGCAGTACGATCGCACGCCCCATGAGAACGATAGGTAAACCTGGTGTCCTGTGAGCGACAAAAGCTTAAATGG\n\n" "2. SMILIES:\n" ":D :) :o :P :/\n\n" "3. EMAIL ADDRESSES:\n" "foo@demo.net \n" "bar.ba@test.co.uk\n\n" "4. HTML Tags:\n" "<p>The <a class=\"APILink\" target=\"_blank\" href=\"https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html\"><code>Pattern</code></a> API contains a number of useful <i>predefined character classes</i>, which offer convenient shorthands for commonly used regular expressions:</p>\n" "<p><a name=\"CHART\" id=\"CHART\"></a></p>\n\n" "5. PHONE NUMBERS:\n" "555.123.4567 \n" "+1-800-555-2468 \n" "+49 7743 9901\n\n" "6. URLs:\n" "www.demo.com \n" "http://foo.co.uk/\n\n" "7. MACHO MAN RANDY SAVAGE QUOTATIONS:\n\n" "“History beckons the Nacho Man.”\n\n" "“Hulkamania is like a single grain of sand in the Sahara desert that is Nacho Madness.”\n\n" "\"Snap into a Slim Jim!\"\n\n" "9. CITATIONS:\n" "We based our calculations on previously published methods (Nadeu 2006).\n\n" "We also used a support vector machine, which is a classification method that is able to deal with highly variable data (Camps-Valls et al. 2004). \n\n" "The population of this species...where the presence and transmission of introduced avian malaria (Plasmodium relictum) is low (Eggert et al. 2008, Dziel et al. 2010)") 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