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

/
/
gm

Test String

Code Generator

Generated Code

use strict; my $str = '<h3>Disabilities Reported</h3> <p><img src="https://chart.apis.google.com/chart?chtt=Disabilities Reported&amp;chs=500x200&amp;chco=76A4FB,224499,FF0000,80C65A,00FF00,FFC020&amp;chxt=x,y&amp;chxl=0:||1:|0%|25%|50%|75%|100%&amp;cht=bvg&amp;chd=t:80|16|1|4|1|5&amp;chdl=Blindness - 80%|Low Vision/Visually-Impaired - 16%|Cognitive - 1%|Deafness/Hard-of-Hearing - 4%|Motor - 2%|No disability - 5%&amp;chbh=30" alt="Disabilities Reported"/></p> <div style="width:100%;"> <table style="width:90%;text-align:left;"> <caption>Which of the following disabilities do you have?</caption> <tr><th>Response</th><th># of Respondents</th><th>% of Respondents</th></tr> <tr><td>Blindness</td><td>898</td><td>80.1%</td></tr> <tr><td>Low Vision/Visually-Impaired</td><td>177</td><td>15.8%</td></tr> <tr><td>Cognitive</td><td>8</td><td>.7%</td></tr> <tr><td>Deafness/Hard-of-Hearing</td><td>47</td><td>4.2%</td></tr> <tr><td>Motor</td><td>24</td><td>2.1%</td></tr> <tr><td>No disability</td><td>60</td><td>5.4%</td></tr> </table> </div> <p>Users could select multiple options. 118 respondents (10.4%) reported multiple disabilities. 52 (4.6%) reported blindness and low vision/visually impaired. 33 respondents (2.9%) reported being both deaf and blind.</p> <h3>Computer and Screen Reader Proficiency</h3> <p><img alt=\'Pie Chart of Computer Proficiency\' src=\'https://chart.apis.google.com/chart?chxt=x,y&amp;chtt=Computer Proficiency&amp;cht=p3&amp;chl=Expert|Advanced|Intermediate|Beginner&amp;chs=500x200&amp;chd=t:22,44,27,8\'></p> <div style="width:100%;"> <table style="width:70%;text-align:left;"> <caption>Please rate your computer proficiency</caption> <tr><th>Response</th><th>% of Respondents</th></tr> <tr><td>Expert</td><td>22%</td></tr> <tr><td>Advanced</td><td>44%</td></tr> <tr><td>Intermediate</td><td>27%</td></tr> <tr><td>Beginner</td><td>8%</td></tr> </table> </div> <p><img alt=\'Pie Chart of Screen Reader Proficiency\' src=\'https://chart.apis.google.com/chart?chxt=x,y&amp;chtt=Screen Reader Proficiency&amp;cht=p3&amp;chl=Expert|Advanced|Intermediate|Beginner&amp;chs=500x200&amp;chd=t:17,41,32,9\'></p> <div style="width:100%;"> <table style="width:70%;text-align:left;"> <caption>Please rate your screen reader proficiency</caption> <tr><th>Response</th><th>% of Respondents</th></tr> <tr><td>Expert</td><td>17%</td></tr> <tr><td>Advanced</td><td>41%</td></tr> <tr><td>Intermediate</td><td>32%</td></tr> <tr><td>Beginner</td><td>9%</td></tr> </table> </div> <p>The responses for computer proficiency and screen reader proficiency were similar. Those who use screen readers for evaluation rated their screen reader proficiency much lower (80% chose Beginner or Intermediate) than those that always use screen readers (only 37% chose Beginner or Intermediate).</p> <h3>Screen Reader Usage</h3> <p><img src="https://chart.apis.google.com/chart?chtt=Screen reader types&amp;chs=450x200&amp;chco=76A4FB,224499,FF0000,80C65A&amp;chxt=x,y&amp;chxl=0:||1:|0%|25%|50%|75%|100%&amp;cht=bvg&amp;chd=t:74|23|8|6&amp;chdl=JAWS - 74%|Window-Eyes - 23%|NVDA - 8%|VoiceOver - 6%&amp;chbh=40" alt="Screen Reader Types"/></p> <p>Of the 1121 respondents, 74% use JAWS, 23% use Window-Eyes, 8% use NVDA, and 6% use VoiceOver. While several other screen readers were reported, these were the most prominently reported. Individual versions of screen readers are not yet computed, but generally the majority of users are using the most up-to-date version of their screen reader.</p> <h3 id="updates">Screen Reader Updates</h3> <p><img alt=\'Screen Reader Updates\' src=\'https://chart.apis.google.com/chart?chxt=x,y&amp;chtt=Screen%20Reader%20Updates&amp;cht=p3&amp;chl=Immediately|First 6 months|6-12 months|1-2 years|2-3 years|3+ years|No response&amp;chs=500x200&amp;chd=t:41,25,9,9,4,6,6\'></p> <div style="width:100%;"> <table style="width:70%;text-align:left;"> <caption>How soon do you update your screen reader after a new version is released?</caption> <tr><th>Upgrade Window</th><th>% of Respondents</th></tr> <tr><td>Immediately</td><td>41%</td></tr> <tr><td>First 6 months</td><td>25%</td></tr> <tr><td>6-12 months</td><td>9%</td></tr> <tr><td>1-2 years</td><td>9%</td></tr> <tr><td>2-3 years</td><td>4%</td></tr> <tr><td>3+ years</td><td>6%</td></tr> <tr><td>No response</td><td>6%</td></tr> </table> </div> <p>Most respondents update their screen reader version soon after a new version is released (74.6% within the first year). However, a significant number of users may still be using screen readers that are 3 years old or older.</p> <h3>Screen Reader Customization</h3> <p><img alt=\'Screen Reader Customization\' src=\'https://chart.apis.google.com/chart?chxt=x,y&amp;chtt=Screen%20Reader%20Customization&amp;cht=p3&amp;chl=A lot|Somewhat|Slightly|Not at all|No response&amp;chs=500x200&amp;chd=t:29,40,21,7,4\'></p> <div style="width:100%;"> <table style="width:70%;text-align:left;"> <caption>How customized are your screen reader settings? (e.g., changed verbosity, installed scripts, etc.)</caption> <tr><th>Response</th><th>% of Respondents</th></tr> <tr><td>A lot</td><td>29%</td></tr> <tr><td>Somewhat</td><td>40%</td></tr> <tr><td>Slightly</td><td>21%</td></tr> <tr><td>Not at all</td><td>7%</td></tr> <tr><td>No response</td><td>4%</td></tr> </table> </div> <p>Most screen reader users customize their screen readers. Those that reported no disability are much less likely to customize their screen readers - a lot or some customization was reported by only 27.6% of respondents with no disability versus 71.4% for those that reported blindness.</p> <h3>Hardware Devices</h3> <p><img src="https://chart.apis.google.com/chart?chtt=Hardware Devices&amp;chs=300x200&amp;chco=76A4FB,80C65A,FF0000&amp;chxt=x,y&amp;chxl=0:||1:|0%|25%|50%|75%|100%&amp;cht=bvg&amp;chd=t:78|54|12&amp;chdl=Desktop - 78%|Laptop - 54%|Mobile phone - 12%&amp;chbh=40" alt="Hardware Devices"/></p> <p>78% of respondents reported using a screen reader on a desktop computer, 54% use a screen reader on a laptop, and 12% use a screen reader on a mobile phone. While many respondents report using a BrailleNote, PacMate, PDA or other devices, the totals for these has not yet been calculated and are not included in the numbers reported above. No respondents who use screen readers for evaluation reported using a screen reader on a mobile device.</p> <h3 id="browsers">Browsers</h3> <p><img src="https://chart.apis.google.com/chart?chtt=Browsers used&amp;chs=380x200&amp;chco=76A4FB,224499,FF0000,80C65A,00FF00,FFC020&amp;chxt=x,y&amp;chxl=0:||1:|0%|25%|50%|75%|100%&amp;cht=bvg&amp;chd=t:33|68|2|39|6&amp;chdl=IE6 - 33%|IE7 - 68%|IE8 - 2%|Firefox - 39%|Safari - 6%&amp;chbh=40" alt="Graph of browsers used"/></p> <div style="width:100%;"> <table style="width:70%;text-align:left;"> <caption>Which web browser(s) do you currently use with a screen reader?</caption> <tr><th>Browser</th><th>% of Respondents</th></tr> <tr><td>IE6</td><td>33%</td></tr> <tr><td>IE7</td><td>68%</td></tr> <tr><td>IE8</td><td>2%</td></tr> <tr><td>Firefox</td><td>39%</td></tr> <tr><td>Safari</td><td>6%</td></tr> </table> </div> <p>Respondents with no disability were nearly twice as likely to list Firefox as blind respondents - 66% to 37%.</p> <p><strong>Note:</strong> The survey question did not ask for the predominant browser used, but for any browsers used with a screen reader. IE8 and Safari numbers were from free-form responses (i.e., they were not listed as available options to select). The percentage of Safari users is over double that of the overall population - this may be due in part to the fact that some in the Mac community actively solicited survey participation and encouraged respondents to indicate their Safari use, perhaps partially due to feeling snubbed because we didn\'t list them with IE and Firefox as direct choices.</p> </div>'; my $regex = qr/<table.*?>(([\s*].*(\s*))+)?<\/table>/mp; if ( $str =~ /$regex/g ) { print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n"; # print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n"; # print "Capture Group 2 is $2 ... and so on\n"; } # ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p' # Named capture groups can be called via $+{name}

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 Perl, please visit: http://perldoc.perl.org/perlre.html