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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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 = '/(((\w\d+|\w+)(\W+)?)?(\s+)?(U;)?(\s+)?(CrOS|Cross|CrossOS))(\s+)(x86_64|x8664|x86_x64|armv\d+|aarch\d+|i\d+|amd64)/mi'; $str = ' 331 Mozilla/5.0 (X11; U; CrOS i686 0.9.128; ru) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.343 Safari/534.10 638 Mozilla/5.0 (X11; U; CrOS i686 0.9.128; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.343 Safari/534.10 661 Mozilla/5.0 (X11; U; CrOS i686 0.9.128; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.341 Safari/534.10 667 Mozilla/5.0 (X11; U; CrOS i686 0.13.507) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36 744 Mozilla/5.0 (X11; U; CrOS i686 0.13.507) AppleWebKit/600.7.12 (KHTML, like Gecko) Version/8.0.7 Safari/600.7.12 903 Mozilla/5.0 (X11; U; CrOS i686 9.10.0; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.253.0 Safari/532.5 949 Mozilla/5.0 (x11; Cross x86_64 12739.105.0) Applewebkit/537.36 (KHTML, like gecko)Chrome/80.0.3987.158 Safari/537.36 1147 Mozilla/5.0 (Wizyconf CrOS x86_64 11021.111.2020 9c7514400ffe) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.124 Safari/537.36 1200 Mozilla/5.0 (X11; CrOS x8664 6680.78.0) AppleWebKit/537.36 (KHTML like Gecko) Chrome/41.0.2272.102 Safari/537.36 1376 Mozilla/5.0 (X11; CrOS x8664 5978.98.1) AppleWebKit/537.36 (KHTML like Gecko) Chrome/37.0.2062.120 Safari/537.36 1513 Mozilla/5.0 (X11; U; CrOS i686 0.13.507) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.94 Safari/535.1 1560 Mozilla/5.0 (X11;CrOS aarch64 13099.85.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.4147.110 Safari/537.36 1917 Mozilla/5.0 (X11CrOS i686 2268.111.0) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11 1935 Mozilla/5.0 (X11; CrOS x8664 5978.80.0) AppleWebKit/537.36 (KHTML like Gecko) Chrome/37.0.2062.119 Safari/537.36 2036 Mozilla/5.0 (X11; CrOS x86_x64 8787.87.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.8787.87 Safari/537.36 2140 Mozilla/5.0 (Wizyconf CrOS x86_64 11021.111.2020 9c7514400083) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.124 Safari/537.36 2289 Mozilla/5.0 (Wizyconf CrOS x86_64 11021.111.2021 9c7514400083) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.124 Safari/537.36 2716 Mozilla/5.0 (Linxus; Android 11; CrOS x86_64 13904.97.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Mobile Safari/537.36 2790 Mozilla/5.0 (Wizyconf CrOS x86_64 13904.98.2021 9c7514400083) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.167 Safari/537.36 2851 Mozilla/5.0 (Wizyconf CrOS x86_64 13904.98.2021 ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.167 Safari/537.36 2989 Mozilla/5.0 (Wizyconf CrOS x86_64 11021.111.2019 9c7514400511) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.124 Safari/537.36 3037 Mozilla/5.0 (X11; Windows x86_64 13904.97.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.167 Safari/537.36 CitrixChromeApp 3107 Mozilla/5.0 (Android <Android Version>; Microsoft) AppleWebKit/<WebKit Rev> (KHTML, like Gecko) Chrome/62.0.3202.66 Mobile Safari/534.30 Edge/<EdgeHTML Rev> 3212 Mozilla/5.0 (X11; CROSSOS amd64) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Safari/605.1.15 3303 Mozilla/5.0 (Wayland; CrOS x86_64;POV_TV-HDMI-200BT Build/JRO03H14268.67.0) AppleWebKit/605.1.15 (KHTML, like Gecko) Chrome/100.0.3770.100 Safari/605.1.15 3304 Mozilla/5.0 (Wayland; CrOS x86_64 14268.67.0) AppleWebKit/605.1.15 (KHTML, like Gecko) Chrome/100.0.3770.100 Safari/605.1.15 3379 Mozilla/5.0 (X11; Windows x86_64 14388.52.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.91 Safari/537.36 CitrixChromeApp 4395 Mozilla/5.0 (X11;CrOS armv7i 13982.88.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36 [ip:79.25.95.226] 4396 Mozilla/5.0 (X11;CrOS armv7i 13982.88.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36 Mozilla/5.0 (X11; CrOS x86_64 14150.7.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.12 Safari/537.36 Mozilla/5.0 (X11; CrOS i686 7077.123.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36 Mozilla/5.0 (X11; CrOS x86_64 13748.0.2021) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4395.3 Safari/537.36 Mozilla/5.0 (X11; CrOS aarch64 14150.3.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.5 Safari/537.36 Mozilla/5.0 (X11; CrOS x86_64 13982.82.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.157 Safari/537.36,gzip(gfe) Mozilla/5.0 (X11; CrOS aarch64 13982.75.2021) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.138 Safari/537.36 Mozilla/5.0 (X11; CrOS aarch64 14150.7.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.12 Safari/537.36 Mozilla/5.0 (X11; CrOS x86_64 13816.93.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.230 Safari/537.36 Mozilla/5.0 (X11; CrOS x86_64 13794.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4418.0 Safari/537.36 Mozilla/5.0 (X11; CrOS aarch64 13505.100.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.142 Safari/537.36 Mozilla/5.0 (X11; CrOS x86_64 14092.32.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.46 Safari/537.36 Mozilla/5.0 (X11; CrOS x86_64 12499.38.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.69 Safari/537.36 Mozilla/5.0 (X11; CrOS x86_64 13982.84.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36 Mozilla/5.0 (X11; CrOS x86_64 14092.35.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.16 Safari/537.36 '; 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