-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
268 lines (261 loc) · 9 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Regex</title>
<script src="https://unpkg.com/lodash@4.17.21/lodash.min.js"></script>
<script src="https://unpkg.com/petite-vue"></script>
<script src="regex-petite-vue.js"></script>
<script>
function togglecheatsheet() {
cheatsheet = document.querySelector("#cheatsheet .content");
if (cheatsheet.style.visibility == "visible") {
cheatsheet.style.visibility = "hidden";
} else { // "hidden" or undefined
cheatsheet.style.visibility = "visible";
}
}
</script>
<script type="module">
PetiteVue.createApp(
{
query: 'f(o)+\\S+',
input: 'table football, foosball',
regex_flags: "g",
get getmarked() {
return marked(this.query, this.input, this.regex_flags);
},
get getmatches() {
return matches(this.query, this.input, this.regex_flags);
},
update_query: _.debounce(function (e) {
this.query = e.target.value
}, 100),
update_input: _.debounce(function (e) {
this.input = e.target.value
}, 100),
}).mount('#editor');
</script>
<script type="module" src="regex-petite-vue.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="editor">
<h1>Regex Static</h1>
<div class="label">Your regular expression:</div>
<div class="query">
/<input :value="query" @input="update_query"></textarea>/
</div>
<!--<div class="flags">
<i Ignore Casing Makes the expression search case-insensitively.
g Global Makes the expression search for all occurrences.
s Dot All Makes the wild character . match newlines as well.
m Multiline Makes the boundary characters ^ and $ match the beginning and ending of every single line instead of the beginning and ending of the whole string.
y Sticky Makes the expression start its searching from the index indicated in its lastIndex property.
u Unicode
</div>-->
<div class="content">
<div class="label">Your test string:</div>
<textarea class="input" :value="input" @input="update_input"></textarea>
<div class="output">
<div>
<div class="label">Match result:</div>
<div class="marked" v-html="getmarked"></div>
</div>
<div>
<div class="label">Match captures: <a id="download" type="text/csv">Download CSV</a></div>
<div class="matches" v-html="getmatches"></div>
</div>
</div>
</div>
<div id="cheatsheet">
<div class="header" onclick="togglecheatsheet()">
Regular expression cheatsheet
</div>
<div class="content">
<div>
<h3>Special characters</h3>
<div class="round">
<table>
<tbody>
<tr>
<th><code>\</code></th>
<td>escape special characters</td>
</tr>
<tr>
<th><code>.</code></th>
<td>matches any character</td>
</tr>
<tr>
<th><code>^</code></th>
<td>matches beginning of string</td>
</tr>
<tr>
<th><code>$</code></th>
<td>matches end of string</td>
</tr>
<tr>
<th><code>[5b-d]</code></th>
<td>matches any chars '5', 'b', 'c' or 'd'</td>
</tr>
<tr>
<th><code>[^a-c6]</code></th>
<td>matches any char except 'a', 'b', 'c' or '6'</td>
</tr>
<tr>
<th><code>R|S</code></th>
<td>matches either regex <code>R</code> or regex <code>S</code></th>
</tr>
<tr>
<th><code>()</code></th>
<td>creates a capture group and indicates precedence</td>
</tr>
</tbody>
</table>
</div>
</div>
<div>
<h3>Quantifiers</h3>
<div class="round">
<table>
<tbody>
<tr>
<th><code>*</code></th>
<td>0 or more (append <code>?</code> for non-greedy)</td>
</tr>
<tr>
<th><code>+</code></th>
<td>1 or more (append <code>?</code> for non-greedy)</td>
</tr>
<tr>
<th><code>?</code></th>
<td>0 or 1 (append <code>?</code> for non-greedy)</td>
</tr>
<tr>
<th><code>{m}</code></th>
<td>exactly <code>m</code>m occurrences</td>
</tr>
<tr>
<th><code>{m, n}</code></th>
<td>from <code>m</code> to <code>n</code>. <code>m</code> defaults to 0, <code>n</code> to infinity
</td>
</tr>
<tr>
<th><code>{m, n}?</code></th>
<td>from <code>m</code> to <code>n</code>, as few as possible</td>
</tr>
</tbody>
</table>
</div>
</div>
<div>
<h3>Special sequences</h3>
<div class="round">
<table>
<tbody>
<tr>
<th><code>\A</code></th>
<td>start of string</td>
</tr>
<tr>
<th><code>\b</code></th>
<td>matches empty string at word boundary (between <code>\w</code> and <code>\W</code>)</td>
</tr>
<tr>
<th><code>\B</code></th>
<td>matches empty string not at word boundary</td>
</tr>
<tr>
<th><code>\d</code></th>
<td>digit</td>
</tr>
<tr>
<th><code>\D</code></th>
<td>non-digit</td>
</tr>
<tr>
<th><code>\s</code></th>
<td>whitespace: <code>[ \t\n\r\f\v]</code></th>
</tr>
<tr>
<th><code>\S</code></th>
<td>non-whitespace</td>
</tr>
<tr>
<th><code>\w</code></th>
<td>alphanumeric: <code>[0-9a-zA-Z_]</code></th>
</tr>
<tr>
<th><code>\W</code></th>
<td>non-alphanumeric</td>
</tr>
<tr>
<th><code>\Z</code></th>
<td>end of string</td>
</tr>
<tr>
<th><code>\g<id></code></th>
<td>matches a previously defined group</td>
</tr>
</tbody>
</table>
</div>
</div>
<div>
<h3>Special sequences</h3>
<div class="round">
<table>
<tbody>
<tr>
<th><code>(?iLmsux)</code></th>
<td>matches empty string, sets re.X flags</td>
</tr>
<tr>
<th><code>(?:...)</code></th>
<td>non-capturing version of regular parentheses</td>
</tr>
<tr>
<th><code>(?P<name>...)</name></code></th>
<td>matches whatever matched previously named group</td>
</tr>
<tr>
<th><code>(?P=<name>)</name></code></th>
<td>digit</td>
</tr>
<tr>
<th><code>(?#...)</code></th>
<td>a comment; ignored</td>
</tr>
<tr>
<th><code>(?=...)</code></th>
<td>lookahead assertion: matches without consuming</td>
</tr>
<tr>
<th><code>(?!...)</code></th>
<td>negative lookahead assertion</td>
</tr>
<tr>
<th><code>(?<=...)</code></th>
<td>lookbehind assertion: matches if preceded</td>
</tr>
<tr>
<th><code>(?<!...)</code></th>
<td>negative lookbehind assertion</td>
</tr>
<tr>
<th><code>(?(id)yes|no)</code></th>
<td>match 'yes' if group 'id' matched, else 'no'</td>
</tr>
</tbody>
</table>
</div>
</div>
<!--<div id="python-regex-cheatsheet-credit">
Based on tartley's <a href="https://github.com/tartley/python-regex-cheatsheet/">python-regex-cheatsheet</a>.
</div>-->
</div>
</div>
</div>
</body>
</html>