Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • 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 single character of: a, b, c or d
    [[ab][cd]]
  • 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]
  • Character class intersection
    [\w&&[^\d]]
  • 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
No Match

"
"
gm

Test String

Code Generator

Generated Code

$re = '/\d{4}(?>-\d{2}){2} \d{2}(?>:\d{2}){2}\,\d{3}\|[ A-Z]{5}\|.*/m'; $str = '2022-04-13 17:00:00,000|DEBUG|WebContainer : 31 |MnmServletFilter | [MNMLOG] CATEGORY=FILTER,TYPE=SERVLET_ACTION,ACTION=SERVLET_BEGIN,CLASS=tw.com.iisi.gaia.mnm.MnmServletFilter,THREAD_NAME=WebContainer : 31,THREAD_ID=1409,SESSION_ID=\'null\',AUTH_TYPE=\'null\',CHAR_ENCODING=\'null\',CONTENT_LENGTH=\'-1\',CONTENT_TYPE=\'null\',CONTEXT_PATH=\'WebApp\',LOCALE=\'zh_TW\',LOCALES={zh_TW},METHOD=\'GET\',PATH_INFO=\'null\',PATH_TRANSLATED=\'null\',PROTOCOL=\'HTTP/1.1\',REMOTE_ADDR=\'10.0.5.61\',REMOTE_HOST=\'etabsmnm\',REMOTE_USER=\'null\',REQUESTED_SESSION_ID=\'null\',REQUEST_URI=\'/WebApp/hg\',COOKIES={},HEADER_PARAMS={User-Agent=\'Jakarta Commons-HttpClient/3.1\',Host=\'10.0.59.37:9080\'},QUERY_STRING=\'null\' 2022-04-13 17:00:01,524|INFO |WebContainer : 31 |GaiaHGServlet | - | - | - | tw.com.iisi.gaia.hg.base.servlet.GaiaHGServlet.doGet(GaiaHGServlet.java:79) | 1945383 | - | [HGSERVLET][10.0.5.61] doGet() called 2022-04-13 17:00:01,524|INFO |WebContainer : 31 |GaiaHGServlet | - | - | - | tw.com.iisi.gaia.hg.base.servlet.GaiaHGServlet.processRequest(GaiaHGServlet.java:89) | 1945384 | - | [HGSERVLET][10.0.5.61] CharacterEncoding: null 2022-04-13 17:00:01,527|INFO |WebContainer : 31 |GaiaHGServlet | - | - | - | tw.com.iisi.gaia.hg.base.servlet.GaiaHGServlet.processRequest(GaiaHGServlet.java:91) | 1945385 | - | [HGSERVLET][10.0.5.61] inputXml: '; 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