Regular Expressions 101

Save & Share

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8

Function

  • Match
  • Substitution
  • List
  • Unit Tests
"
([A-Z][a-z]{2} [A-Z][a-z]{2} \d{2} \d{2}:\d{2}:\d{2} CET \d{4})\n(/dev.*?) ==> (.*?)\n.*?\n(\d*) bytes .*? copied, (.*?) s, (.*?) (.*?s\n)(.*?)Exit status: (\d*)\n
"
gsm
1st Capturing Group
([A-Z][a-z]{2} [A-Z][a-z]{2} \d{2} \d{2}:\d{2}:\d{2} CET \d{4})
Match a single character present in the list below
[A-Z]
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case sensitive)
Match a single character present in the list below
[a-z]
{2} matches the previous token exactly 2 times
a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
matches the character with index 3210 (2016 or 408) literally (case sensitive)
Match a single character present in the list below
[A-Z]
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case sensitive)
Match a single character present in the list below
[a-z]
{2} matches the previous token exactly 2 times
a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
matches the character with index 3210 (2016 or 408) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
{2} matches the previous token exactly 2 times
matches the character with index 3210 (2016 or 408) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
{2} matches the previous token exactly 2 times
: matches the character : with index 5810 (3A16 or 728) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
{2} matches the previous token exactly 2 times
: matches the character : with index 5810 (3A16 or 728) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
{2} matches the previous token exactly 2 times
CET
matches the characters CET literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
{4} matches the previous token exactly 4 times
\n matches a line-feed (newline) character (ASCII 10)
2nd Capturing Group
(/dev.*?)
/dev
matches the characters /dev literally (case sensitive)
.
matches any character
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
==>
matches the characters ==> literally (case sensitive)
3rd Capturing Group
(.*?)
.
matches any character
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
\n matches a line-feed (newline) character (ASCII 10)
.
matches any character
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
\n matches a line-feed (newline) character (ASCII 10)
4th Capturing Group
(\d*)
\d
matches a digit (equivalent to [0-9])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
bytes
matches the characters bytes literally (case sensitive)
.
matches any character
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
copied,
matches the characters copied, literally (case sensitive)
5th Capturing Group
(.*?)
.
matches any character
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
s,
matches the characters s, literally (case sensitive)
6th Capturing Group
(.*?)
matches the character with index 3210 (2016 or 408) literally (case sensitive)
7th Capturing Group
(.*?s\n)
8th Capturing Group
(.*?)
Exit status:
matches the characters Exit status: literally (case sensitive)
9th Capturing Group
(\d*)
\n matches a line-feed (newline) character (ASCII 10)
Global pattern flags
g modifier: global. All matches (don't return after first match)
s modifier: single line. Dot matches newline characters
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
Your regular expression does not match the subject string.

Regular Expression
No Match

r"
"
gsm

Test String