You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: regex.html
+93-15Lines changed: 93 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,17 @@
23
23
background:#F4E5E5;
24
24
}
25
25
26
+
/* sidebar */
27
+
.bs-docs-sidebar {
28
+
padding-left:20px;
29
+
margin-top:20px;
30
+
margin-bottom:20px;
31
+
}
32
+
33
+
.fixed {
34
+
position: fixed;
35
+
}
36
+
26
37
@media print {
27
38
/* Overrides bootstrap's' stylesheet: don't show URLs when printing */
28
39
a[href]:after {
@@ -32,6 +43,11 @@
32
43
td.na {
33
44
background:#EEE;
34
45
}
46
+
47
+
/* sidebar */
48
+
.bs-docs-sidebar {
49
+
display: none;
50
+
}
35
51
}
36
52
</style>
37
53
@@ -48,30 +64,37 @@
48
64
</div>
49
65
50
66
<divclass="container" role="main">
67
+
<divclass="row">
68
+
<divclass="col-md-9">
51
69
52
70
<divclass="hidden-print">
53
-
<h1>Regex cheatsheet</h1>
54
-
55
-
<p>Many programs use regular expression to find & replace text. However, they tend to come with their own different flavor.</p>
56
-
<p>You can probably expect most modern software and programming languages to be using some variation of the Perl flavor, "PCRE"; however command-line tools (grep, less, ...) will often use the POSIX flavor (sometimes with an extended variant, e.g. <code>egrep</code> or <code>sed -r</code>). ViM also comes with its own syntax (a superset of what Vi accepts).</p>
57
-
<p>This cheatsheet lists the respective <ahref="#syntax">syntax of each flavor</a>, and the <ahref="#programs">software that uses it</a>.</p>
58
-
<p>If you spot errors or missing data, or just want to make this prettier/more accurate, don't hesitate to open an <ahref="https://github.com/remram44/regex-cheatsheet/issues/new">issue</a> or a <ahref="https://github.com/remram44/regex-cheatsheet/compare/">pull request</a>.</p>
71
+
<sectionid="intro" class="group">
72
+
<h1>Regex cheatsheet</h1>
73
+
74
+
<p>Many programs use regular expression to find & replace text. However, they tend to come with their own different flavor.</p>
75
+
<p>You can probably expect most modern software and programming languages to be using some variation of the Perl flavor, "PCRE"; however command-line tools (grep, less, ...) will often use the POSIX flavor (sometimes with an extended variant, e.g. <code>egrep</code> or <code>sed -r</code>). ViM also comes with its own syntax (a superset of what Vi accepts).</p>
76
+
<p>This cheatsheet lists the respective <ahref="#syntax">syntax of each flavor</a>, and the <ahref="#programs">software that uses it</a>.</p>
77
+
<p>If you spot errors or missing data, or just want to make this prettier/more accurate, don't hesitate to open an <ahref="https://github.com/remram44/regex-cheatsheet/issues/new">issue</a> or a <ahref="https://github.com/remram44/regex-cheatsheet/compare/">pull request</a>.</p>
<tr><td>Custom character class</td><td><code>[...]</code></td><td><code>[...]</code></td><td><code>[...]</code></td><td><code>[...]</code></td><td><code>[...]</code></td></tr>
70
91
<tr><td>Negated custom character class</td><td><code>[^...]</code></td><td><code>[^...]</code></td><td><code>[^...]</code></td><td><code>[^...]</code></td><td><code>[^...]</code></td></tr>
71
92
<tr><td>\ special in class?</td><td>yes</td><td>yes</td><td>no, <code>]</code> escaped if comes first</td><td></td><td></td></tr>
72
93
<tr><td>Ranges</td><td><code>[a-z]</code>, <code>-</code> escaped if comes last</td><td><code>[a-z]</code>, <code>-</code> escaped if first or last</td><td><code>[a-z]</code>, <code>-</code> escaped if comes last</td><td></td><td><code>[a-z]</code></td></tr>
<tr><td>Any character (except newline)</td><td><code>.</code></td><td><code>.</code></td><td><code>.</code></td><td><code>.</code></td><td><code>.</code></td></tr>
77
100
<tr><td>Any character (including newline)</td><tdclass="na"></td><tdclass="na"></td><tdclass="na"></td><tdclass="na"></td><td><code>\_.</code></td></tr>
<tr><td>Character equivalents (e = é = è) (as per locale)</td><td></td><tdclass="na"></td><td><code>[[=e=]]</code></td><td><code>[[=e=]]</code></td><td><code>[[=e=]]</code></td></tr>
<tr><td>Backreference to a specific group.</td><td><code>\1</code><code>\g1</code><code>\g{-1}</code></td><td><code>\1</code></td><td><code>\1</code></td><td><code>\1</code> non-official</td><td><code>\1</code></td></tr>
<tr><td>0 or 1, non-greedy</td><td><code>??</code></td><td><code>??</code></td><tdclass="na"></td><tdclass="na"></td><td></td></tr>
115
-
<tr><td>0 or more, non-greedy</td><td><code>*?</code></td><td><code>*?</code></td><tdclass="na"></td><tdclass="na"></td><td><code>\{-}</code></td></tr>
116
-
<tr><td>1 or more, non-greedy</td><td><code>+?</code></td><td><code>+?</code></td><tdclass="na"></td><tdclass="na"></td><td></td></tr>
<tr><td>0 or 1, non-greedy</td><td><code>?+</code></td><td><code>??</code></td><tdclass="na"></td><tdclass="na"></td><td></td></tr>
146
+
<tr><td>0 or more, non-greedy</td><td><code>*+</code></td><td><code>*?</code></td><tdclass="na"></td><tdclass="na"></td><td><code>\{-}</code></td></tr>
147
+
<tr><td>1 or more, non-greedy</td><td><code>++</code></td><td><code>+?</code></td><tdclass="na"></td><tdclass="na"></td><td></td></tr>
<tr><td>0 or 1, don't give back on backtrack</td><td><code>?+</code></td><tdclass="na"></td><tdclass="na"></td><tdclass="na"></td><tdclass="na"></td></tr>
119
150
<tr><td>0 or more, don't give back on backtrack</td><td><code>*+</code></td><tdclass="na"></td><tdclass="na"></td><tdclass="na"></td><tdclass="na"></td></tr>
120
151
<tr><td>1 or more, don't give back on backtrack</td><td><code>++</code></td><tdclass="na"></td><tdclass="na"></td><tdclass="na"></td><tdclass="na"></td></tr>
121
152
<tr><td>Specific number, don't give back on backtrack</td><td><code>{n,m}+</code><code>{n,}?</code></td><tdclass="na"></td><tdclass="na"></td><tdclass="na"></td><tdclass="na"></td></tr>
<tr><td><ahref="http://perldoc.perl.org/perlre.html">Perl</a></td><td>PCRE</td><td>PCRE is actually a separate implementation from Perl's, with <ahref="http://en.wikipedia.org/wiki/Perl_Compatible_Regular_Expressions#Differences_from_Perl">slight differences</a></td></tr>
137
172
<tr><td><ahref="https://docs.python.org/library/re.html">Python's <code>re</code> standard lib</a></td><td>Python's own syntax (Perl-inspired)</td><td></td></tr>
138
173
<tr><td><ahref="http://ruby-doc.org/core-2.2.0/Regexp.html">Ruby</a></td><td>Ruby's own syntax (Perl-inspired)</td><td></td></tr>
0 commit comments