Skip to content

Commit b12f797

Browse files
committed
Merge pull request #7 from remram44/sections
Adds dynamic navigation sidebar
2 parents d38fdb2 + 832fbaa commit b12f797

File tree

1 file changed

+93
-15
lines changed

1 file changed

+93
-15
lines changed

regex.html

Lines changed: 93 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@
2323
background: #F4E5E5;
2424
}
2525

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+
2637
@media print {
2738
/* Overrides bootstrap's' stylesheet: don't show URLs when printing */
2839
a[href]:after {
@@ -32,6 +43,11 @@
3243
td.na {
3344
background: #EEE;
3445
}
46+
47+
/* sidebar */
48+
.bs-docs-sidebar {
49+
display: none;
50+
}
3551
}
3652
</style>
3753

@@ -48,30 +64,37 @@
4864
</div>
4965

5066
<div class="container" role="main">
67+
<div class="row">
68+
<div class="col-md-9">
5169

5270
<div class="hidden-print">
53-
<h1>Regex cheatsheet</h1>
54-
55-
<p>Many programs use regular expression to find &amp; 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 <a href="#syntax">syntax of each flavor</a>, and the <a href="#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 <a href="https://github.com/remram44/regex-cheatsheet/issues/new">issue</a> or a <a href="https://github.com/remram44/regex-cheatsheet/compare/">pull request</a>.</p>
71+
<section id="intro" class="group">
72+
<h1>Regex cheatsheet</h1>
73+
74+
<p>Many programs use regular expression to find &amp; 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 <a href="#syntax">syntax of each flavor</a>, and the <a href="#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 <a href="https://github.com/remram44/regex-cheatsheet/issues/new">issue</a> or a <a href="https://github.com/remram44/regex-cheatsheet/compare/">pull request</a>.</p>
78+
</section>
5979
</div>
6080

61-
<h1 id="syntax">Syntax</h1>
81+
<section id="syntax" class="group">
82+
<h1>Syntax</h1>
6283

6384
<table class="table table-bordered table-striped">
6485
<thead>
6586
<tr><th>What</th><th><a href="http://perldoc.perl.org/perlre.html">Perl</a>/PCRE</th><th><a href="https://docs.python.org/library/re.html">Python's <code>re</code></a></th><th>POSIX (BRE)</th><th>POSIX extended (ERE)</th><th>ViM</th></tr>
6687
</thead>
67-
<tbody>
88+
<tbody id="syntax-basics" class="subgroup">
6889
<tr><th colspan="6">Basics</th></tr>
6990
<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>
7091
<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>
7192
<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>
7293
<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>
7394
<tr><td>Alternation</td><td><code>|</code></td><td><code>|</code></td><td class="na"></td><td><code>|</code></td><td><code>\|</code> <code>\&amp;</code> (low precedence)</td></tr>
7495
<tr><td>Escaped character</td><td><code>\033</code> <code>\x1B</code> <code>\x{1234}</code> <code>\N{name}</code> <code>\N{U+263D}</code></td><td><code>\x12</code></td><td class="na"></td><td class="na"></td><td><code>\%d123</code> <code>\%x2A</code> <code>\%u1234</code> <code>\%U1234ABCD</code></td></tr>
96+
</tbody>
97+
<tbody id="syntax-characters" class="subgroup">
7598
<tr><th colspan="6">Character classes</th></tr>
7699
<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>
77100
<tr><td>Any character (including newline)</td><td class="na"></td><td class="na"></td><td class="na"></td><td class="na"></td><td><code>\_.</code></td></tr>
@@ -91,52 +114,66 @@ <h1 id="syntax">Syntax</h1>
91114
<tr><td>Any alphanumerical character</td><td><code>[[:alnum:]]</code></td><td class="na"></td><td><code>[[:alnum:]]</code></td><td><code>[[:alnum:]]</code></td><td><code>[[:alnum:]]</code></td></tr>
92115
<tr><td>ASCII</td><td><code>[[:ascii:]]</code></td><td class="na"></td><td><code>[[:ascii:]]</code></td><td><code>[[:ascii:]]</code></td><td class="na"></td></tr>
93116
<tr><td>Character equivalents (e = é = è) (as per locale)</td><td></td><td class="na"></td><td><code>[[=e=]]</code></td><td><code>[[=e=]]</code></td><td><code>[[=e=]]</code></td></tr>
117+
</tbody>
118+
<tbody id="syntax-assert" class="subgroup">
94119
<tr><th colspan="6">Zero-width assertions</th></tr>
95120
<tr><td>Word boundary</td><td><code>\b</code></td><td><code>\b</code></td><td class="na"></td><td class="na"></td><td><code>\&lt;</code> / <code>\&gt;</code></td></tr>
96121
<tr><td>Anywhere but word boundary</td><td><code>\B</code></td><td><code>\B</code></td><td class="na"></td><td class="na"></td><td class="na"></td></tr>
97122
<tr><td>Beginning of line/string</td><td><code>^</code> / <code>\A</code></td><td><code>^</code> / <code>\A</code></td><td><code>^</code></td><td><code>^</code></td><td><code>^</code> (beginning of pattern ) <code>\_^</code></td></tr>
98123
<tr><td>End of line/string</td><td><code>$</code> / <code>\Z</code></td><td><code>$</code> / <code>\Z</code></td><td><code>$</code></td><td><code>$</code></td><td><code>$</code> (end of pattern) <code>\_$</code></td></tr>
124+
</tbody>
125+
<tbody id="syntax-groups" class="subgroup">
99126
<tr><th colspan="6">Captures and groups</th></tr>
100127
<tr><td>Capturing group</td><td><code>(...)</code> <code>(?&lt;name&gt;...)</code></td><td><code>(...)</code> <code>(?P&lt;name&gt;...)</code></td><td><code>\(...\)</code></td><td><code>(...)</code></td><td><code>\(...\)</code></td></tr>
101128
<tr><td>Non-capturing group</td><td><code>(?:...)</code></td><td><code>(?:...)</code></td><td class="na"></td><td class="na"></td><td><code>\%(...\)</code></td></tr>
102129
<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>
103130
<tr><td>Named backreference</td><td><code>\g{name}</code> <code>\k&lt;name&gt;</code></td><td><code>(?P=name)</code></td><td class="na"></td><td class="na"></td><td class="na"></td></tr>
131+
</tbody>
132+
<tbody id="syntax-lookaround" class="subgroup">
104133
<tr><th colspan="6">Look-around</th></tr>
105134
<tr><td>Positive look-ahead</td><td><code>(?=...)</code></td><td><code>(?=...)</code></td><td class="na"></td><td class="na"></td><td><code>\(...\)\@=</code></td></tr>
106135
<tr><td>Negative look-ahead</td><td><code>(?!...)</code></td><td><code>(?!...)</code></td><td class="na"></td><td class="na"></td><td><code>\(...\)\@!</code></td></tr>
107136
<tr><td>Positive look-behind</td><td><code>(?&lt;=...)</code></td><td><code>(?&lt;=...)</code></td><td class="na"></td><td class="na"></td><td><code>\(...\)\@&lt;=</code></td></tr>
108137
<tr><td>Negative look-behind</td><td><code>(?&lt;!...)</code></td><td><code>(?&lt;!...)</code></td><td class="na"></td><td class="na"></td><td><code>\(...\)\@&lt;!</code></td></tr>
138+
</tbody>
139+
<tbody id="syntax-multiplicity" class="subgroup">
109140
<tr><th colspan="6">Multiplicity</th></tr>
110141
<tr><td>0 or 1</td><td><code>?</code></td><td><code>?</code></td><td><code>\?</code></td><td><code>?</code></td><td><code>\?</code></td></tr>
111142
<tr><td>0 or more</td><td><code>*</code></td><td><code>*</code></td><td><code>*</code></td><td><code>*</code></td><td><code>*</code></td></tr>
112143
<tr><td>1 or more</td><td><code>+</code></td><td><code>+</code></td><td><code>\+</code></td><td><code>+</code></td><td><code>\+</code></td></tr>
113144
<tr><td>Specific number</td><td><code>{n}</code> <code>{n,m}</code> <code>{n,}</code></td><td><code>{n}</code> <code>{n,m}</code> <code>{n,}</code></td><td><code>\{n\}</code> <code>\{n,m\}</code> <code>\{n,\}</code></td><td><code>{n}</code> <code>{n,m}</code> <code>{n,}</code></td><td><code>\{n}</code> <code>\{n,m}</code> <code>\{n,}</code></td></tr>
114-
<tr><td>0 or 1, non-greedy</td><td><code>??</code></td><td><code>??</code></td><td class="na"></td><td class="na"></td><td></td></tr>
115-
<tr><td>0 or more, non-greedy</td><td><code>*?</code></td><td><code>*?</code></td><td class="na"></td><td class="na"></td><td><code>\{-}</code></td></tr>
116-
<tr><td>1 or more, non-greedy</td><td><code>+?</code></td><td><code>+?</code></td><td class="na"></td><td class="na"></td><td></td></tr>
117-
<tr><td>Specific number, non-greedy</td><td><code>{n,m}?</code> <code>{n,}?</code></td><td><code>{n,m}?</code> <code>{n,}?</code></td><td class="na"></td><td class="na"></td><td><code>\{-n,m}</code> <code>\{-n,}</code></td></tr>
145+
<tr><td>0 or 1, non-greedy</td><td><code>?+</code></td><td><code>??</code></td><td class="na"></td><td class="na"></td><td></td></tr>
146+
<tr><td>0 or more, non-greedy</td><td><code>*+</code></td><td><code>*?</code></td><td class="na"></td><td class="na"></td><td><code>\{-}</code></td></tr>
147+
<tr><td>1 or more, non-greedy</td><td><code>++</code></td><td><code>+?</code></td><td class="na"></td><td class="na"></td><td></td></tr>
148+
<tr><td>Specific number, non-greedy</td><td><code>{n,m}+</code> <code>{n,}+</code></td><td><code>{n,m}?</code> <code>{n,}?</code></td><td class="na"></td><td class="na"></td><td><code>\{-n,m}</code> <code>\{-n,}</code></td></tr>
118149
<tr><td>0 or 1, don't give back on backtrack</td><td><code>?+</code></td><td class="na"></td><td class="na"></td><td class="na"></td><td class="na"></td></tr>
119150
<tr><td>0 or more, don't give back on backtrack</td><td><code>*+</code></td><td class="na"></td><td class="na"></td><td class="na"></td><td class="na"></td></tr>
120151
<tr><td>1 or more, don't give back on backtrack</td><td><code>++</code></td><td class="na"></td><td class="na"></td><td class="na"></td><td class="na"></td></tr>
121152
<tr><td>Specific number, don't give back on backtrack</td><td><code>{n,m}+</code> <code>{n,}?</code></td><td class="na"></td><td class="na"></td><td class="na"></td><td class="na"></td></tr>
153+
</tbody>
154+
<tbody id="syntax-other" class="subgroup">
122155
<tr><th colspan="6">Other</th></tr>
123156
<tr><td>Independent non-backtracking pattern</td><td><code>(?&gt;...)</code></td><td class="na"></td><td class="na"></td><td class="na"></td><td><code>\(...\)\@&gt;</code></td></tr>
124157
<tr><td>Make case-sensitive/insensitive</td><td><code>(?i)</code> / <code>(?-i)</code></td><td><code>(?i)</code> / <code>(?-i)</code></td><td class="na"></td><td class="na"></td><td><code>\c</code> / <code>\C</code></td></tr>
125158
</tbody>
126159
</table>
160+
</section>
127161

128-
<h1 id="programs">Programs</h1>
162+
<section id="programs" class="group">
163+
<h1>Programs</h1>
129164

130165
<table class="table table-bordered table-striped">
131166
<thead>
132167
<tr><th>What</th><th>Syntax</th><th>Comments/gotchas</th></tr>
133168
</thead>
134-
<tbody>
169+
<tbody id="programs-languages" class="subgroup">
135170
<tr><th colspan="3">Programming languages</th></tr>
136171
<tr><td><a href="http://perldoc.perl.org/perlre.html">Perl</a></td><td>PCRE</td><td>PCRE is actually a separate implementation from Perl's, with <a href="http://en.wikipedia.org/wiki/Perl_Compatible_Regular_Expressions#Differences_from_Perl">slight differences</a></td></tr>
137172
<tr><td><a href="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>
138173
<tr><td><a href="http://ruby-doc.org/core-2.2.0/Regexp.html">Ruby</a></td><td>Ruby's own syntax (Perl-inspired)</td><td></td></tr>
139174
<tr><td><a href="http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html">Java's java.util.regex</a></td><td>Almost PCRE</td><td></td></tr>
175+
</tbody>
176+
<tbody id="programs-editors" class="subgroup">
140177
<tr><th colspan="3">Text editors</th></tr>
141178
<tr><td>Eclipse</td><td>PCRE</td><td></td></tr>
142179
<tr><td>Emacs</td><td>?</td><td></td></tr>
@@ -146,6 +183,8 @@ <h1 id="programs">Programs</h1>
146183
<tr><td>Sublime Text</td><td>?</td><td></td></tr>
147184
<tr><td>UltraEdit</td><td>PCRE</td><td></td></tr>
148185
<tr><td>ViM</td><td>ViM</td><td></td></tr>
186+
</tbody>
187+
<tbody id="programs-cmdline" class="subgroup">
149188
<tr><th colspan="3">Command-line tools</th></tr>
150189
<tr><td>awk</td><td>?</td><td></td></tr>
151190
<tr><td>grep</td><td>BRE, <code>-E</code> for ERE, <code>-P</code> for PCRE (optional)</td><td>OS X?</td></tr>
@@ -154,7 +193,39 @@ <h1 id="programs">Programs</h1>
154193
<tr><td>sed</td><td>BRE, <code>-r</code> switches to ERE</td><td>OS X?</td></tr>
155194
</tbody>
156195
</table>
157-
196+
</section>
197+
198+
</div>
199+
200+
<nav class="col-md-3 bs-docs-sidebar">
201+
<ul id="sidebar" class="nav nav-stacked fixed">
202+
<li>
203+
<a href="#intro">Introduction</a>
204+
</li>
205+
<li>
206+
<a href="#syntax">Syntax</a>
207+
<ul class="nav nav-stacked">
208+
<li><a href="#syntax-basics">Basics</a></li>
209+
<li><a href="#syntax-characters">Character classes</a></li>
210+
<li><a href="#syntax-assert">Zero-width assertions</a></li>
211+
<li><a href="#syntax-groups">Captures and groups</a></li>
212+
<li><a href="#syntax-lookaround">Look-around</a></li>
213+
<li><a href="#syntax-multiplicity">Multiplicity</a></li>
214+
<li><a href="#syntax-other">Other</a></li>
215+
</ul>
216+
</li>
217+
<li>
218+
<a href="#programs">Programs</a>
219+
<ul class="nav nav-stacked">
220+
<li><a href="#programs-languages">Programming languages</a></li>
221+
<li><a href="#programs-editors">Text editors</a></li>
222+
<li><a href="#programs-cmdline">Command-line tools</a></li>
223+
</ul>
224+
</li>
225+
</ul>
226+
</nav>
227+
228+
</div>
158229
</div>
159230

160231
<!-- Bootstrap core JavaScript
@@ -165,5 +236,12 @@ <h1 id="programs">Programs</h1>
165236
<!--<script src="js/docs.min.js"></script>-->
166237
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
167238
<script src="js/ie10-viewport-bug-workaround.js"></script>
239+
240+
<script>
241+
$('body').scrollspy({
242+
target: '.bs-docs-sidebar',
243+
offset: 40
244+
});
245+
</script>
168246
</body>
169247
</html>

0 commit comments

Comments
 (0)