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

@"
"
gm

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"\d+.+\d{4}(?:-\d{2}){2} (?:\d{2}:){2}[\d.]+$|^Index.+Time$"; string input = @"screen-length disable display nqa history *********************************************************************** * * * * * * * _____ _ _ _____ _ _ * * / ____| (_) | | / ____| | | (_) * * | |___ __ _ _ _ __ | |_ ___ | | __ ___ | |__ __ _ _ _ __ * * \___ \ / _` | | '_ \| __||___|| | |_ |/ _ \| '_ \ / _` | | '_ \ * * ____) | (_| | | | | | |_ | |__| | (_) | |_) | (_| | | | | | * * |_____/ \__,_|_|_| |_|\__| \_____|\___/|_.__/ \__,_|_|_| |_| * * * * * * * * EQX * * * *---------------------------------------------------------------------* * * * DIS01 * * * * * * This network of computers is protected by a security system. * * Criminal law prohibits unauthorized use. * * Violators will be prosecuted. * *********************************************************************** ****************************************************************************** * Copyright (c) 2010-2019 Hewlett Packard Enterprise Development LP * * Without the owner's prior written consent, * * no decompiling or reverse-engineering shall be allowed. * ****************************************************************************** <DIS01>screen-length disable <DIS01>display nqa history NQA entry (admin cgadmin, tag isl_latency) history records: Index Response Status Time 2618 3 Succeeded 2022-10-07 17:11:35.9 2617 2 Succeeded 2022-10-07 17:06:35.9 2616 2 Succeeded 2022-10-07 17:01:35.9 2615 2 Succeeded 2022-10-07 16:56:35.9 2614 2 Succeeded 2022-10-07 16:51:35.9 2613 3 Succeeded 2022-10-07 16:46:35.9 2612 3 Succeeded 2022-10-07 16:41:35.9 2611 3 Succeeded 2022-10-07 16:36:35.9 2610 3 Succeeded 2022-10-07 16:31:35.9 2609 2 Succeeded 2022-10-07 16:26:35.9 2608 2 Succeeded 2022-10-07 16:21:35.9 2607 2 Succeeded 2022-10-07 16:16:35.9 2606 2 Succeeded 2022-10-07 16:11:35.9 2605 2 Succeeded 2022-10-07 16:06:35.9 2604 2 Succeeded 2022-10-07 16:01:35.9 2603 2 Succeeded 2022-10-07 15:56:35.9 2602 2 Succeeded 2022-10-07 15:51:35.9 2601 3 Succeeded 2022-10-07 15:46:35.9 2600 2 Succeeded 2022-10-07 15:41:35.9 2599 2 Succeeded 2022-10-07 15:36:35.9 2598 3 Succeeded 2022-10-07 15:31:35.9 2597 4 Succeeded 2022-10-07 15:26:35.9 2596 3 Succeeded 2022-10-07 15:21:35.9 2595 3 Succeeded 2022-10-07 15:16:35.9 2594 3 Succeeded 2022-10-07 15:11:35.9 2593 2 Succeeded 2022-10-07 15:06:35.9 2592 3 Succeeded 2022-10-07 15:01:35.9 2591 2 Succeeded 2022-10-07 14:56:35.9 2590 3 Succeeded 2022-10-07 14:51:35.9 2589 3 Succeeded 2022-10-07 14:46:35.9 2588 2 Succeeded 2022-10-07 14:41:35.9 2587 3 Succeeded 2022-10-07 14:36:35.9 2586 2 Succeeded 2022-10-07 14:31:35.9 2585 2 Succeeded 2022-10-07 14:26:35.9 2584 2 Succeeded 2022-10-07 14:21:35.9 2583 3 Succeeded 2022-10-07 14:16:35.9 2582 2 Succeeded 2022-10-07 14:11:35.9 2581 3 Succeeded 2022-10-07 14:06:35.9 2580 2 Succeeded 2022-10-07 14:01:35.9 2579 2 Succeeded 2022-10-07 13:56:35.9 2578 3 Succeeded 2022-10-07 13:51:35.9 2577 2 Succeeded 2022-10-07 13:46:35.9 2576 2 Succeeded 2022-10-07 13:41:35.9 2575 2 Succeeded 2022-10-07 13:36:35.9 2574 2 Succeeded 2022-10-07 13:31:35.9 2573 2 Succeeded 2022-10-07 13:26:35.9 2572 3 Succeeded 2022-10-07 13:21:35.9 2571 3 Succeeded 2022-10-07 13:16:35.9 <DIS01>"; RegexOptions options = RegexOptions.Multiline; foreach (Match m in Regex.Matches(input, pattern, options)) { Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index); } } }

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 C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx