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 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

/
/
gm

Test String

Code Generator

Generated Code

$re = '/^(?P<date>[^\s]+)\s+(?P<time>[^\s]+)\s+(?P<time_taken>[^\s]+)\s+(?P<c_ip>[^\s]+)\s+(?P<cs_username>[^\s]+)\s+(?P<cs_auth_group>[^\s]+)\s+(?P<x_exception_id>[^\s]+)\s+(?P<filter_result>[^\s]+).*?\"(?P<category>[^\"]+)\"\s+(?P<http_referrer>[^\s]+)\s+(?P<sc_status>[^\s]+)\s+(?P<action>[^\s]+)\s+(?P<cs_method>[^\s]+)\s+(?P<http_content_type>[^\s]+)\s+(?P<cs_uri_scheme>[^\s]+)\s+(?P<cs_host>[^\s]+)\s+(?P<cs_uri_port>[^\s]+)\s+(?P<cs_uri_path>[^\s]+)\s+(?P<cs_uri_query>[^\s]+)\s+(?P<cs_uri_extension>[^\s]+)\s+\"(?P<http_user_agent>[^\"]+)\"\s+(?P<s_ip>[^\s]+)\s+(?P<sc_bytes>[^\s]+)\s+(?P<cs_bytes>[^\s]+)\s+\"?(?P<x_virus_id>[^\"]+)\"?\s+\"(?P<x_bluecoat_application_name>[^\"]+)\"\s+\"(?P<x_bluecoat_application_operation>[^\"]+)\"/m'; $str = ' 2015-11-05 16:01:53 54 10.0.19.44 hammlx1 - - OBSERVED "Web Ads/Analytics" http://bcp.crwdcntrl.net/5/c=1226/rand=328960996/pv=y/int=%23OpR%2358075%23DailyMail%20%3A%20Time%20of%20Day%20%3A%2010AM%C2%A0/int=%23OpR%2358689%23Dailymail%20%3A%20Weather-current-description%20%3A%20Cloudy%20with%20outbreaks%20of%20Rain/int=%23OpR%2358690%23Dailymail%20%3A%20Weather-current-temperature%20%3A%2043%C2%B0F/int=%23OpR%2358691%23Dailymail%20%3A%20Weather-upcoming-description%20%3A%20Scattered%20Showers/int=%23OpR%2358692%23Dailymail%20%3A%20Weather-upcoming-temperature%20%3A%2046%C2%B0F/med=%23OpR%2350629%23DailyMail%20%3A%20Home%20Page%20Date%20%3A%20Thursday%2C%20Nov%205th%202015/seg=%23OpR%2350561%23Date%20%3A%20Thursday%2C%20Nov%205th%202015/ug=%23OpR%2350557%23GrapeShot%20%3A%20Channel%20%3A%20gv_weightwatchers/ug=%23OpR%2350558%23GrapeShot%20%3A%20Channel%20%3A%20gv_weightwatchers/ug=%23OpR%2350559%23GrapeShot%20%3A%20US%20Channel%20%3A%20us_negative_crime/ug=%23OpR%2350560%23GrapeShot%20%3A%20US%20Channel%20%3A%20us_negative_crime/genp=%23OpR%2330426%23Site%20Section%20%3A%20index/genp=%23OpR%2330427%23Site%20Section%20%3A%20ushome/rt=ifr 204 TCP_NC_MISS GET image/png;charset=UTF-8 http su.addthis.com 80 /red/usync ?pid=11127&puid=ce5754badf674f9ba73d138adc3e8e1a - "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko" 10.0.2.248 451 2394 - "none" "none" 2015-11-05 16:05:14 763 10.80.64.129 cajones - us-ads.openx.net 173.241.244.221 None - - PROXIED "Web Ads/Analytics" http://lagrangenews.com/news/5895/students-strive-to-serve 200 TCP_NC_MISS GET application/json http us-ads.openx.net 80 /w/1.0/acj ?o=5040266117&callback=OX_5040266117&ju=http%3A//lagrangenews.com/news/5895/students-strive-to-serve&jr=http%3A//lagrangenews.com/&auid=538038002&dims=1419x731&adxy=0%2C0&res=1440x900x32&plg=pm&ch=utf-8&tz=300&ws=1419x731&ifr=0&tws=1419x731&vmt=1&bi=66daec33-f482-4821-b52e-7f07e884dfe3&sd=29 - "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; Media Center PC 6.0; BRI/2)" 10.75.95.91 1906 2550 - "none" "none" none'; 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