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
  • 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

/
/
ig

Test String

Code Generator

Generated Code

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "('providers' => \\[)([^[\\]]*)(\\n \\],)"; final String string = "<?php\n\n" + "return [\n\n" + " /*\n" + " |--------------------------------------------------------------------------\n" + " | Application Environment\n" + " |--------------------------------------------------------------------------\n" + " |\n" + " | This value determines the \"environment\" your application is currently\n" + " | running in. This may determine how you prefer to configure various\n" + " | services your application utilizes. Set this in your \".env\" file.\n" + " |\n" + " */\n\n" + " 'env' => env('APP_ENV', 'production'),\n\n" + " /*\n" + " |--------------------------------------------------------------------------\n" + " | Application Debug Mode\n" + " |--------------------------------------------------------------------------\n" + " |\n" + " | When your application is in debug mode, detailed error messages with\n" + " | stack traces will be shown on every error that occurs within your\n" + " | application. If disabled, a simple generic error page is shown.\n" + " |\n" + " */\n\n" + " 'debug' => env('APP_DEBUG', false),\n\n" + " /*\n" + " |--------------------------------------------------------------------------\n" + " | Application URL\n" + " |--------------------------------------------------------------------------\n" + " |\n" + " | This URL is used by the console to properly generate URLs when using\n" + " | the Artisan command line tool. You should set this to the root of\n" + " | your application so that it is used when running Artisan tasks.\n" + " |\n" + " */\n\n" + " 'url' => env('API_URL', 'http://localhost'),\n\n" + " /*\n" + " |--------------------------------------------------------------------------\n" + " | Application Timezone\n" + " |--------------------------------------------------------------------------\n" + " |\n" + " | Here you may specify the default timezone for your application, which\n" + " | will be used by the PHP date and date-time functions. We have gone\n" + " | ahead and set this to a sensible default for you out of the box.\n" + " |\n" + " */\n\n" + " 'timezone' => 'CET',\n\n" + " /*\n" + " |--------------------------------------------------------------------------\n" + " | Application Locale Configuration\n" + " |--------------------------------------------------------------------------\n" + " |\n" + " | The application locale determines the default locale that will be used\n" + " | by the translation service provider. You are free to set this value\n" + " | to any of the locales which will be supported by the application.\n" + " |\n" + " */\n\n" + " 'locale' => 'fr',\n\n" + " /*\n" + " |--------------------------------------------------------------------------\n" + " | Application Fallback Locale\n" + " |--------------------------------------------------------------------------\n" + " |\n" + " | The fallback locale determines the locale to use when the current one\n" + " | is not available. You may change the value to correspond to any of\n" + " | the language folders that are provided through your application.\n" + " |\n" + " */\n\n" + " 'fallback_locale' => 'en',\n\n" + " /*\n" + " |--------------------------------------------------------------------------\n" + " | Encryption Key\n" + " |--------------------------------------------------------------------------\n" + " |\n" + " | This key is used by the Illuminate encrypter service and should be set\n" + " | to a random, 32 character string, otherwise these encrypted strings\n" + " | will not be safe. Please do this before deploying an application!\n" + " |\n" + " */\n\n" + " 'key' => env('APP_KEY'),\n\n" + " 'cipher' => 'AES-256-CBC',\n\n" + " /*\n" + " |--------------------------------------------------------------------------\n" + " | Logging Configuration\n" + " |--------------------------------------------------------------------------\n" + " |\n" + " | Here you may configure the log settings for your application. Out of\n" + " | the box, Laravel uses the Monolog PHP logging library. This gives\n" + " | you a variety of powerful log handlers / formatters to utilize.\n" + " |\n" + " | Available Settings: \"single\", \"daily\", \"syslog\", \"errorlog\"\n" + " |\n" + " */\n\n" + " 'log' => env('APP_LOG', 'single'),\n\n" + " /*\n" + " |--------------------------------------------------------------------------\n" + " | Autoloaded Service Providers\n" + " |--------------------------------------------------------------------------\n" + " |\n" + " | The service providers listed here will be automatically loaded on the\n" + " | request to your application. Feel free to add your own services to\n" + " | this array to grant expanded functionality to your applications.\n" + " |\n" + " */\n\n" + " 'providers' => [\n\n" + " /*\n" + " * Laravel Framework Service Providers...\n" + " */\n" + " Illuminate\\Auth\\AuthServiceProvider::class,\n" + " Illuminate\\Broadcasting\\BroadcastServiceProvider::class,\n" + " Illuminate\\Bus\\BusServiceProvider::class,\n" + " Illuminate\\Cache\\CacheServiceProvider::class,\n" + " Illuminate\\Foundation\\Providers\\ConsoleSupportServiceProvider::class,\n" + " Illuminate\\Cookie\\CookieServiceProvider::class,\n" + " Illuminate\\Database\\DatabaseServiceProvider::class,\n" + " Illuminate\\Encryption\\EncryptionServiceProvider::class,\n" + " Illuminate\\Filesystem\\FilesystemServiceProvider::class,\n" + " Illuminate\\Foundation\\Providers\\FoundationServiceProvider::class,\n" + " Illuminate\\Hashing\\HashServiceProvider::class,\n" + " Illuminate\\Mail\\MailServiceProvider::class,\n" + " Illuminate\\Pagination\\PaginationServiceProvider::class,\n" + " Illuminate\\Pipeline\\PipelineServiceProvider::class,\n" + " Illuminate\\Queue\\QueueServiceProvider::class,\n" + " Illuminate\\Redis\\RedisServiceProvider::class,\n" + " Illuminate\\Auth\\Passwords\\PasswordResetServiceProvider::class,\n" + " Illuminate\\Session\\SessionServiceProvider::class,\n" + " Illuminate\\Translation\\TranslationServiceProvider::class,\n" + " Illuminate\\Validation\\ValidationServiceProvider::class,\n" + " Illuminate\\View\\ViewServiceProvider::class,\n\n" + " /*\n" + " * Application Service Providers...\n" + " */\n" + " App\\Providers\\AppServiceProvider::class,\n" + " App\\Providers\\AuthServiceProvider::class,\n" + " App\\Providers\\EventServiceProvider::class,\n" + " App\\Providers\\RouteServiceProvider::class,\n\n" + " ],\n\n" + " /*\n" + " |--------------------------------------------------------------------------\n" + " | Class Aliases\n" + " |--------------------------------------------------------------------------\n" + " |\n" + " | This array of class aliases will be registered when this application\n" + " | is started. However, feel free to register as many as you wish as\n" + " | the aliases are \"lazy\" loaded so they don't hinder performance.\n" + " |\n" + " */\n\n" + " 'aliases' => [\n\n" + " 'App' => Illuminate\\Support\\Facades\\App::class,\n" + " 'Artisan' => Illuminate\\Support\\Facades\\Artisan::class,\n" + " 'Auth' => Illuminate\\Support\\Facades\\Auth::class,\n" + " 'Blade' => Illuminate\\Support\\Facades\\Blade::class,\n" + " 'Cache' => Illuminate\\Support\\Facades\\Cache::class,\n" + " 'Config' => Illuminate\\Support\\Facades\\Config::class,\n" + " 'Cookie' => Illuminate\\Support\\Facades\\Cookie::class,\n" + " 'Crypt' => Illuminate\\Support\\Facades\\Crypt::class,\n" + " 'DB' => Illuminate\\Support\\Facades\\DB::class,\n" + " 'Eloquent' => Illuminate\\Database\\Eloquent\\Model::class,\n" + " 'Event' => Illuminate\\Support\\Facades\\Event::class,\n" + " 'File' => Illuminate\\Support\\Facades\\File::class,\n" + " 'Gate' => Illuminate\\Support\\Facades\\Gate::class,\n" + " 'Hash' => Illuminate\\Support\\Facades\\Hash::class,\n" + " 'Lang' => Illuminate\\Support\\Facades\\Lang::class,\n" + " 'Log' => Illuminate\\Support\\Facades\\Log::class,\n" + " 'Mail' => Illuminate\\Support\\Facades\\Mail::class,\n" + " 'Password' => Illuminate\\Support\\Facades\\Password::class,\n" + " 'Queue' => Illuminate\\Support\\Facades\\Queue::class,\n" + " 'Redirect' => Illuminate\\Support\\Facades\\Redirect::class,\n" + " 'Redis' => Illuminate\\Support\\Facades\\Redis::class,\n" + " 'Request' => Illuminate\\Support\\Facades\\Request::class,\n" + " 'Response' => Illuminate\\Support\\Facades\\Response::class,\n" + " 'Route' => Illuminate\\Support\\Facades\\Route::class,\n" + " 'Schema' => Illuminate\\Support\\Facades\\Schema::class,\n" + " 'Session' => Illuminate\\Support\\Facades\\Session::class,\n" + " 'Storage' => Illuminate\\Support\\Facades\\Storage::class,\n" + " 'URL' => Illuminate\\Support\\Facades\\URL::class,\n" + " 'Validator' => Illuminate\\Support\\Facades\\Validator::class,\n" + " 'View' => Illuminate\\Support\\Facades\\View::class,\n\n" + " ],\n\n" + "];\n"; final Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html