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

/
/
gmi

Test String

Code Generator

Generated Code

$re = '/((maildir=cipec\.com\.br.*\/)|(clearpasswd.*\,))/mi'; $str = '3-Sep 1 08:40:59 srvmail authdaemond: password matches successfully 4-Sep 1 08:40:59 srvmail authdaemond: authmysql: sysusername=<null>, sysuserid=5000, sysgroupid=5000, homedir=/home/vmail, address=helio@cipec.com.br, fullname=<null>, maildir=cipec.com.br/helio/, quota=<null>, options=<null> 5:Sep 1 08:40:59 srvmail authdaemond: authmysql: clearpasswd=<null>, passwd=pdsPDnYTP3gyw 6-Sep 1 08:40:59 srvmail authdaemond: Authenticated: sysusername=<null>, sysuserid=5000, sysgroupid=5000, homedir=/home/vmail, address=helio@cipec.com.br, fullname=<null>, maildir=cipec.com.br/helio/, quota=<null>, options=<null> 7:Sep 1 08:40:59 srvmail authdaemond: Authenticated: clearpasswd=hel733, passwd=pdsPDnYTP3gyw 8-Sep 1 08:40:59 srvmail pop3d: LOGIN, user=helio@cipec.com.br, ip=[::ffff:10.0.1.103], port=[46999] 9-Sep 1 08:40:59 srvmail pop3d: LOGOUT, user=helio@cipec.com.br, ip=[::ffff:10.0.1.103], port=[46999], top=0, retr=0, rcvd=12, sent=39, time=0 -- 42-Sep 1 08:41:02 srvmail authdaemond: password matches successfully 43-Sep 1 08:41:02 srvmail authdaemond: authmysql: sysusername=<null>, sysuserid=5000, sysgroupid=5000, homedir=/home/vmail, address=antonio@cipec.com.br, fullname=<null>, maildir=cipec.com.br/antonio/, quota=<null>, options=<null> 44:Sep 1 08:41:02 srvmail authdaemond: authmysql: clearpasswd=<null>, passwd=pdiHUG4qjaDnI 45-Sep 1 08:41:02 srvmail authdaemond: Authenticated: sysusername=<null>, sysuserid=5000, sysgroupid=5000, homedir=/home/vmail, address=antonio@cipec.com.br, fullname=<null>, maildir=cipec.com.br/antonio/, quota=<null>, options=<null> 46:Sep 1 08:41:02 srvmail authdaemond: Authenticated: clearpasswd=ant527, passwd=pdiHUG4qjaDnI 47-Sep 1 08:41:02 srvmail pop3d: LOGIN, user=antonio@cipec.com.br, ip=[::ffff:10.0.1.103], port=[47004] 48-Sep 1 08:41:02 srvmail postgrey[1708]: action=pass, reason=client AWL, client_name=cipec.com.br, client_address=201.48.59.65, sender=return@bonustelecom.com.br, recipient=bianca@cipec.com.br -- 73-Sep 1 08:41:04 srvmail authdaemond: password matches successfully 74-Sep 1 08:41:04 srvmail authdaemond: authmysql: sysusername=<null>, sysuserid=5000, sysgroupid=5000, homedir=/home/vmail, address=davi@cipec.com.br, fullname=<null>, maildir=cipec.com.br/davi/, quota=<null>, options=<null> 75:Sep 1 08:41:04 srvmail authdaemond: authmysql: clearpasswd=<null>, passwd=u3WErgO7RPtDc 76-Sep 1 08:41:04 srvmail authdaemond: Authenticated: sysusername=<null>, sysuserid=5000, sysgroupid=5000, homedir=/home/vmail, address=davi@cipec.com.br, fullname=<null>, maildir=cipec.com.br/davi/, quota=<null>, options=<null> 77:Sep 1 08:41:04 srvmail authdaemond: Authenticated: clearpasswd=dav510, passwd=u3WErgO7RPtDc 78-Sep 1 08:41:04 srvmail pop3d: LOGIN, user=davi@cipec.com.br, ip=[::ffff:10.0.1.103], port=[47017] 79-Sep 1 08:41:04 srvmail pop3d: LOGOUT, user=davi@cipec.com.br, ip=[::ffff:10.0.1.103], port=[47017], top=0, retr=0, rcvd=12, sent=39, time=0 '; 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