Regular Expressions 101

Save & Share

  • Regex Version: ver. 3
  • 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

/
/
gmx

Test String

Code Generator

Generated Code

$re = '/^ (?<Y>\d{4})-(?<M>\d{2})-(?<D>\d{2})\s(?<T>(?:\d\d\.){3}\d{3}) # Datum # 1 mellanslag mellan datum och övrig info (?:\s (?: (?<msg>\p{Lu}+\s\p{Lu}+\s\p{Lu}+\s\p{Lu}+)\s+$ # 4 versala ord, sedan slut | (?<id1>\S+\s?\S+\s?\S+) # 3,2,1 ord \s{1,2} (?<status1>\S+|\S+\s\S+)\s{1,2} # 1,2 ord (?<letter1>\S)?\s*$ # en bokstav i slutet på en rad (med ev. whitespace) ) | # 4 mellanslag mellan datum och övrig info \s{4} (?<id4>\S+\s\S+(?:\s\S+\s\S+)?) # 2,4 ord (?:\s{3}|\s) # 1,3 mellanslag (?: (?<status4>\S+\s?\S+(?:\s\S+)?) # 2,3 ord | # ELLER (?<statusArg>\S+\s{2}) # 1 ord och 2 mellanslag (?<arg>\S+) # 1 ord ) (?:\s{4}|\s{2}) # 2,4 mellanslag (?: (?<letter4>\S) # 1 bokstav \s{2}? # 0,2 mellanslag (?<letter42>\S)?)? \s*$ # ibland finns det två bokstäver (42=4 spaces, 2 bokstav) )/mx'; $str = 'Ny loggfil skapas 2020-06-07 23:50:02 2020-06-08 12.56.36.000 MANUELL ÖVERKOPPLING HAR SKETT 2020-06-08 12.56.37.000 Ethernet anslutning A AC FEL 2020-06-08 12.56.38.000 FIL-SYNKRONISERING STARTAD 2020-06-08 12.56.39.000 Ethernet anslutning B AC FEL 1978-01-01 00.00.00.000 521GW A I DRIFT T 2020-06-08 12.56.53.000 521GW A MV/TTD-LÄNK ANSL. 1978-01-01 00.00.00.000 521FE A.2 I DRIFT T 2020-06-08 12.56.53.000 GW A FELFRI 1978-01-01 00.00.00.000 521PKT 13A/B I DRIFT T 1978-01-01 00.00.00.000 521PKT 14A/B I DRIFT T 2020-06-08 12.56.53.000 PKT NR. 13A/B FELFRI 2020-06-08 12.56.53.000 PKT NR. 14A/B FELFRI 1978-01-01 00.00.00.000 521FE A.1 I DRIFT T 2020-06-08 12.56.54.000 PKT NR. 14A/B HREP S 2020-06-08 12.56.54.000 521FE A.1 MV/TTD-LÄNK ANSL. 2020-06-08 12.56.54.000 FRONT END A:1 FELFRI 1980-01-01 00.00.00.000 521PKT 2 I DRIFT T 2020-06-08 12.56.54.000 PKT NR. 2 FELFRI 1980-01-01 00.00.00.000 521PKT 4 I DRIFT T 1980-01-01 00.00.00.000 521PKT 6 I DRIFT T 2020-06-08 12.56.54.000 521FE A.2 MV/TTD-LÄNK ANSL. 2020-06-08 12.56.54.000 PKT NR. 4 FELFRI 2020-06-08 12.56.54.000 PKT NR. 6 FELFRI 2020-06-08 12.56.54.000 FRONT END A:2 FELFRI 1980-01-01 00.00.00.000 521PKT 12 I DRIFT T 1980-01-01 00.00.00.000 521PKT 8 I DRIFT T 1980-01-01 00.00.00.000 521PKT 10 I DRIFT T 1980-01-01 00.00.00.000 521PKT 5 I DRIFT T 1980-01-01 00.00.00.000 521PKT 3 I DRIFT T 1978-01-01 00.00.00.000 521PKT 14A/B I DRIFT T 2020-06-08 12.56.55.000 PKT NR. 12 FELFRI 2020-06-08 12.56.55.000 PKT NR. 8 FELFRI 2020-06-08 12.56.55.000 PKT NR. 10 FELFRI 2020-06-08 12.56.55.000 PKT NR. 5 FELFRI 2020-06-08 12.56.55.000 PKT NR. 3 FELFRI 2020-06-08 12.56.55.000 PKT NR. 1 HREP S 2020-06-08 12.56.55.000 PKT NR. 14A/B HREP K 2020-06-08 12.56.55.000 PKT NR. 7 HREP S 1980-01-01 00.00.00.000 521PKT 11 I DRIFT T 1980-01-01 00.00.00.000 521PKT 9 I DRIFT T 2020-06-08 12.56.55.000 PKT NR. 11 FELFRI 2020-06-08 12.56.55.000 PKT NR. 9 FELFRI 2020-06-08 12.56.56.000 PKT NR. 1 HREP K 1980-01-01 00.00.00.000 521PKT 7 I DRIFT T 1980-01-01 00.00.00.000 521PKT 1 I DRIFT T 2020-06-08 12.56.56.000 PKT NR. 7 HREP K 2020-06-08 12.56.56.000 PKT NR. 7 FELFRI 2020-06-08 12.56.56.000 PKT NR. 1 FELFRI 2020-06-08 12.57.06.000 521FE B.1 I DRIFT R 2020-06-08 12.57.06.000 FRONT END B:1 FELFRI R 2020-06-08 12.57.07.000 521FE B.2 I DRIFT R 2020-06-08 12.57.07.000 FRONT END B:2 FELFRI R 2020-06-08 12.57.07.000 521GW B I DRIFT R 2020-06-08 12.57.07.000 GW B FELFRI R 2020-06-08 12.57.43.000 FIL-SYNKRONISERING AVSLUTAD 2020-06-08 12.57.51.000 Länk till BIS FEL 2020-06-08 12.58.07.000 Länk till BIS FELFRI 2020-06-08 12.58.52.000 Länk till BIS FEL R 2020-06-08 12.59.07.000 Länk till BIS FELFRI '; 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