Regular Expressions 101

Save & Share

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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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

/
/
gm

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"^\[([\d]{1,2}-[\w]{3,9}-[\d]{4}\s+[\d]{2}:[\d]{2}:[\d]{2}\s+[A-Z]{3,4})\]\s((?s).+?)(?=(?:^\[.+\])|\Z)"; string input = @"[27-May-2021 05:59:39 UTC] Inpsyde\Idealo\WooCommerce\IdealoException: Plugin ""woocommerce"" must be installed and active in C:\Users\xedin\Local Sites\idealo\app\public\wp-content\plugins\idealo-for-woocommerce\src\Application.php:172 [27-May-2021 05:59:39 UTC] PHP Fatal error: Uncaught Error: Class 'ActionScheduler_Lock' not found in C:\Users\xedin\Local Sites\idealo\app\public\wp-content\plugins\idealo-for-woocommerce\vendor\woocommerce\action-scheduler\classes\abstracts\ActionScheduler.php:29 Stack trace: #0 C:\Users\xedin\Local Sites\idealo\app\public\wp-content\plugins\idealo-for-woocommerce\vendor\woocommerce\action-scheduler\classes\ActionScheduler_QueueRunner.php(103): ActionScheduler::lock() #1 C:\Users\xedin\Local Sites\idealo\app\public\wp-includes\class-wp-hook.php(292): ActionScheduler_QueueRunner->maybe_dispatch_async_request('') #2 C:\Users\xedin\Local Sites\idealo\app\public\wp-includes\class-wp-hook.php(316): WP_Hook->apply_filters(NULL, Array) #3 C:\Users\xedin\Local Sites\idealo\app\public\wp-includes\plugin.php(484): WP_Hook->do_action(Array) #4 C:\Users\xedin\Local Sites\idealo\app\public\wp-includes\load.php(1072): do_action('shutdown') #5 [internal function]: shutdown_action_hook() #6 {main} thrown in C:\Users\xedin\Local Sites\idealo\app\public\wp-content\plugins\idealo-for-woocommerce\vendor\woocommerce\action-scheduler\classes\abstracts\ActionScheduler.php on line 29 [27-May-2021 05:59:39 UTC] PHP Stack trace: [27-May-2021 05:59:39 UTC] PHP 1. {main}() C:\Users\xedin\Local Sites\idealo\app\public\wp-admin\admin-ajax.php:0 [27-May-2021 05:59:39 UTC] PHP 2. do_action() C:\Users\xedin\Local Sites\idealo\app\public\wp-admin\admin-ajax.php:187 [27-May-2021 05:59:39 UTC] PHP 3. WP_Hook->do_action() C:\Users\xedin\Local Sites\idealo\app\public\wp-includes\plugin.php:484 [27-May-2021 05:59:39 UTC] PHP 4. WP_Hook->apply_filters() C:\Users\xedin\Local Sites\idealo\app\public\wp-includes\class-wp-hook.php:316 [27-May-2021 05:59:39 UTC] PHP 5. wp_ajax_delete_plugin() C:\Users\xedin\Local Sites\idealo\app\public\wp-includes\class-wp-hook.php:292 [27-May-2021 05:59:39 UTC] PHP 6. wp_send_json_success() C:\Users\xedin\Local Sites\idealo\app\public\wp-admin\includes\ajax-actions.php:4591 [27-May-2021 05:59:39 UTC] PHP 7. wp_send_json() C:\Users\xedin\Local Sites\idealo\app\public\wp-includes\functions.php:4151 [27-May-2021 05:59:39 UTC] PHP 8. wp_die() C:\Users\xedin\Local Sites\idealo\app\public\wp-includes\functions.php:4125 [27-May-2021 05:59:39 UTC] PHP 9. _ajax_wp_die_handler() C:\Users\xedin\Local Sites\idealo\app\public\wp-includes\functions.php:3421 [27-May-2021 06:56:26 UTC] PHP Warning: mysqli_real_connect(): (HY000/2002): No connection could be made because the target machine actively refused it. in C:\Users\xedin\Local Sites\idealo\app\public\wp-includes\wp-db.php on line 1653 [27-May-2021 06:56:27 UTC] PHP Stack trace: [27-May-2021 06:56:27 UTC] PHP 1. {main}() C:\Users\xedin\Local Sites\idealo\app\public\wp-cron.php:0 [27-May-2021 06:56:27 UTC] PHP 2. require_once() C:\Users\xedin\Local Sites\idealo\app\public\wp-cron.php:44 [27-May-2021 06:56:27 UTC] PHP 3. require_once() C:\Users\xedin\Local Sites\idealo\app\public\wp-load.php:37 [27-May-2021 06:56:27 UTC] PHP 4. require_once() C:\Users\xedin\Local Sites\idealo\app\public\wp-config.php:80 [27-May-2021 06:56:27 UTC] PHP 5. require_wp_db() C:\Users\xedin\Local Sites\idealo\app\public\wp-settings.php:124 [27-May-2021 06:56:27 UTC] PHP 6. wpdb->__construct() C:\Users\xedin\Local Sites\idealo\app\public\wp-includes\load.php:545 [27-May-2021 06:56:27 UTC] PHP 7. wpdb->db_connect() C:\Users\xedin\Local Sites\idealo\app\public\wp-includes\wp-db.php:632 [27-May-2021 06:56:27 UTC] PHP 8. mysqli_real_connect() C:\Users\xedin\Local Sites\idealo\app\public\wp-includes\wp-db.php:1653 "; 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