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

$re = '/^(?<Date>[\d\-]{10})? (?<Time>[\d\:\.\+\ ]{19})? (?<Level>\[[A-Z]{3}\]) (?<Message>[\s\S]*?\n*(?=^[\d\-]{10}.*?(?:[^ \n]+ )|\z))/m'; $str = '2018-10-15 15:38:22.685 +02:00 [INF] Configuration Result: [Success] Name GTS.MAUTO.Service [Success] DisplayName GTS MAUTO service [Success] Description Service for standalone mode linked to GTS Vision application. [Success] ServiceName GTS.MAUTO.Service 2018-10-15 15:38:22.729 +02:00 [INF] Topshelf v4.0.0.0, .NET Framework v4.0.30319.42000 2018-10-15 15:38:22.829 +02:00 [INF] Using default implementation for object serializer 2018-10-15 15:38:22.845 +02:00 [INF] Using default implementation for ThreadExecutor 2018-10-15 15:38:22.860 +02:00 [INF] Initialized Scheduler Signaller of type: Quartz.Core.SchedulerSignalerImpl 2018-10-15 15:38:22.860 +02:00 [INF] Quartz Scheduler v.2.6.1.0 created. 2018-10-15 15:38:22.861 +02:00 [INF] JobFactory set to: GTS.Scheduler.AutofacJobFactory 2018-10-15 15:38:22.861 +02:00 [INF] RAMJobStore initialized. 2018-10-15 15:38:22.863 +02:00 [INF] Scheduler meta-data: Quartz Scheduler (v2.6.1.0) \'QuartzScheduler\' with instanceId \'NON_CLUSTERED\' Scheduler class: \'Quartz.Core.QuartzScheduler\' - running locally. NOT STARTED. Currently in standby mode. Number of jobs executed: 0 Using thread pool \'Quartz.Simpl.SimpleThreadPool\' - with 1 threads. Using job-store \'Quartz.Simpl.RAMJobStore\' - which does not support persistence. and is not clustered. 2018-10-15 15:38:22.863 +02:00 [INF] Quartz scheduler \'QuartzScheduler\' initialized 2018-10-15 15:38:22.863 +02:00 [INF] Quartz scheduler version: 2.6.1.0 2018-10-15 15:38:22.888 +02:00 [DBG] Started by the Windows services process 2018-10-15 15:38:22.888 +02:00 [DBG] Running as a service, creating service host. 2018-10-15 15:38:22.889 +02:00 [INF] Starting as a Windows service 2018-10-15 15:38:22.891 +02:00 [DBG] [Topshelf] Starting up as a windows service application 2018-10-15 15:38:22.893 +02:00 [INF] [Topshelf] Starting 2018-10-15 15:38:22.893 +02:00 [DBG] [Topshelf] Current Directory: D:\\GTS_VISION\\MAUTO Service 2018-10-15 15:38:22.893 +02:00 [DBG] [Topshelf] Arguments: 2018-10-15 15:38:22.895 +02:00 [INF] MAUTO Windows Service starting 2018-10-15 15:38:22.994 +02:00 [DBG] Connected to Data Source=localhost;Initial Catalog=IRECVISION_MQB_PROD_LOCAL;Integrated Security=False;User ID=GTSMAUTO;Password=Wysiwyg!;MultipleActiveResultSets=False 2018-10-15 15:38:23.032 +02:00 [DBG] Connected to Data Source=GTSSQL-VISION;Initial Catalog=IRECVISION_MQB_PROD;Integrated Security=False;User ID=GTSMAUTO;Password=Wysiwyg!;MultipleActiveResultSets=False 2018-10-15 15:38:23.033 +02:00 [DBG] Connected to Data Source=localhost;Initial Catalog=IRECVISION_MQB_PROD_LOCAL;Integrated Security=False;User ID=GTSMAUTO;Password=Wysiwyg!;MultipleActiveResultSets=False 2018-10-15 15:38:23.038 +02:00 [DBG] Connected to Data Source=GTSSQL-VISION;Initial Catalog=IRECVISION_MQB_PROD;Integrated Security=False;User ID=GTSMAUTO;Password=Wysiwyg!;MultipleActiveResultSets=False 2018-10-15 15:38:23.040 +02:00 [DBG] Connected to Data Source=localhost;Initial Catalog=IRECVISION_MQB_PROD_LOCAL;Integrated Security=False;User ID=GTSMAUTO;Password=Wysiwyg!;MultipleActiveResultSets=False 2018-10-15 15:38:23.040 +02:00 [DBG] Get MAUTOParameter SELECT [Mp_jetonmaitre] AS [RemoteToken], [Mp_jetonlocal] AS [LocalToken] FROM [dbo].[MAUTOParametre] 2018-10-15 15:38:23.162 +02:00 [ERR] Failed to start service System.Exception: Integrity error, the token of the local base does not correspond to the remote database. à GTS.MAUTO.MAUTOClient.CheckIntegrity() dans D:\\TFS\\Beta\\Quattro.2.x\\Quattro.2.28\\Quattro.2.28.0\\MAUTO\\src\\GTS.MAUTO\\MAUTOClient.cs:ligne 122 à GTS.MAUTO.Service.MAUTOService.Start() dans D:\\TFS\\Beta\\Quattro.2.x\\Quattro.2.28\\Quattro.2.28.0\\MAUTO\\src\\GTS.MAUTO.Service\\MAUTOService.cs:ligne 44 2018-10-15 15:38:23.184 +02:00 [INF] [Topshelf] Started 2018-10-15 15:40:55.598 +02:00 [INF] [Topshelf] Stopping 2018-10-15 15:40:55.599 +02:00 [INF] MAUTO Windows Service stopping 2018-10-15 15:40:55.599 +02:00 [INF] Cron scheduler stopping 2018-10-15 15:40:55.601 +02:00 [INF] Scheduler QuartzScheduler_$_NON_CLUSTERED shutting down. 2018-10-15 15:40:55.601 +02:00 [INF] Scheduler QuartzScheduler_$_NON_CLUSTERED paused. 2018-10-15 15:40:55.604 +02:00 [DBG] Shutting down threadpool... 2018-10-15 15:40:55.604 +02:00 [DBG] Shutdown of threadpool complete. 2018-10-15 15:40:55.604 +02:00 [INF] Scheduler QuartzScheduler_$_NON_CLUSTERED Shutdown complete. 2018-10-15 15:40:55.604 +02:00 [INF] Cron scheduler stopped 2018-10-15 15:40:55.604 +02:00 [INF] MAUTO Windows Service stopped 2018-10-15 15:40:55.606 +02:00 [INF] Cron scheduler stopping 2018-10-15 15:40:55.606 +02:00 [INF] Cron scheduler stopped 2018-10-15 15:40:55.660 +02:00 [INF] [Topshelf] Stopped 2018-10-15 15:40:55.953 +02:00 [DBG] WorkerThread is shut down 2018-10-15 15:42:54.823 +02:00 [INF] Configuration Result: [Success] Name GTS.MAUTO.Service [Success] DisplayName GTS MAUTO service [Success] Description Service for standalone mode linked to GTS Vision application. [Success] ServiceName GTS.MAUTO.Service 2018-10-15 15:42:54.871 +02:00 [INF] Topshelf v4.0.0.0, .NET Framework v4.0.30319.42000 2018-10-15 15:42:54.934 +02:00 [INF] Using default implementation for object serializer 2018-10-15 15:42:54.954 +02:00 [INF] Using default implementation for ThreadExecutor 2018-10-15 15:42:54.979 +02:00 [INF] Initialized Scheduler Signaller of type: Quartz.Core.SchedulerSignalerImpl 2018-10-15 15:42:54.979 +02:00 [INF] Quartz Scheduler v.2.6.1.0 created. 2018-10-15 15:42:54.980 +02:00 [INF] JobFactory set to: GTS.Scheduler.AutofacJobFactory 2018-10-15 15:42:54.980 +02:00 [INF] RAMJobStore initialized. 2018-10-15 15:42:54.982 +02:00 [INF] Scheduler meta-data: Quartz Scheduler (v2.6.1.0) \'QuartzScheduler\' with instanceId \'NON_CLUSTERED\' Scheduler class: \'Quartz.Core.QuartzScheduler\' - running locally. NOT STARTED. Currently in standby mode. Number of jobs executed: 0 Using thread pool \'Quartz.Simpl.SimpleThreadPool\' - with 1 threads. Using job-store \'Quartz.Simpl.RAMJobStore\' - which does not support persistence. and is not clustered. 2018-10-15 15:42:54.982 +02:00 [INF] Quartz scheduler \'QuartzScheduler\' initialized 2018-10-15 15:42:54.982 +02:00 [INF] Quartz scheduler version: 2.6.1.0 2018-10-15 15:42:55.000 +02:00 [DBG] Started by the Windows services process 2018-10-15 15:42:55.000 +02:00 [DBG] Running as a service, creating service host. 2018-10-15 15:42:55.002 +02:00 [INF] Starting as a Windows service 2018-10-15 15:42:55.003 +02:00 [DBG] [Topshelf] Starting up as a windows service application 2018-10-15 15:42:55.005 +02:00 [INF] [Topshelf] Starting 2018-10-15 15:42:55.006 +02:00 [DBG] [Topshelf] Current Directory: D:\\GTS_VISION\\MAUTO Service 2018-10-15 15:42:55.006 +02:00 [DBG] [Topshelf] Arguments: 2018-10-15 15:42:55.007 +02:00 [INF] MAUTO Windows Service starting 2018-10-15 15:42:55.052 +02:00 [DBG] Connected to Data Source=localhost;Initial Catalog=IRECVISION_MQB_PROD_LOCAL;Integrated Security=False;User ID=GTSMAUTO;Password=Wysiwyg!;MultipleActiveResultSets=False 2018-10-15 15:42:55.081 +02:00 [DBG] Connected to Data Source=GTSSQL-VISION;Initial Catalog=IRECVISION_MQB_PROD;Integrated Security=False;User ID=GTSMAUTO;Password=Wysiwyg!;MultipleActiveResultSets=False 2018-10-15 15:42:55.082 +02:00 [DBG] Connected to Data Source=localhost;Initial Catalog=IRECVISION_MQB_PROD_LOCAL;Integrated Security=False;User ID=GTSMAUTO;Password=Wysiwyg!;MultipleActiveResultSets=False 2018-10-15 15:42:55.085 +02:00 [DBG] Connected to Data Source=GTSSQL-VISION;Initial Catalog=IRECVISION_MQB_PROD;Integrated Security=False;User ID=GTSMAUTO;Password=Wysiwyg!;MultipleActiveResultSets=False 2018-10-15 15:42:55.087 +02:00 [DBG] Connected to Data Source=localhost;Initial Catalog=IRECVISION_MQB_PROD_LOCAL;Integrated Security=False;User ID=GTSMAUTO;Password=Wysiwyg!;MultipleActiveResultSets=False 2018-10-15 15:42:55.087 +02:00 [DBG] Get MAUTOParameter SELECT [Mp_jetonmaitre] AS [RemoteToken], [Mp_jetonlocal] AS [LocalToken] FROM [dbo].[MAUTOParametre] 2018-10-15 15:42:55.111 +02:00 [ERR] Failed to start service System.Exception: Integrity error, the token of the local base does not correspond to the remote database. à GTS.MAUTO.MAUTOClient.CheckIntegrity() dans D:\\TFS\\Beta\\Quattro.2.x\\Quattro.2.28\\Quattro.2.28.0\\MAUTO\\src\\GTS.MAUTO\\MAUTOClient.cs:ligne 122 à GTS.MAUTO.Service.MAUTOService.Start() dans D:\\TFS\\Beta\\Quattro.2.x\\Quattro.2.28\\Quattro.2.28.0\\MAUTO\\src\\GTS.MAUTO.Service\\MAUTOService.cs:ligne 44 2018-10-15 15:42:55.118 +02:00 [INF] [Topshelf] Started '; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

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 PHP, please visit: http://php.net/manual/en/ref.pcre.php