Skip to content

Commit e2a1748

Browse files
committed
feat(new tool): added Regex Cheatsheet
1 parent f0a092f commit e2a1748

File tree

7 files changed

+177
-10
lines changed

7 files changed

+177
-10
lines changed

components.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,20 @@ declare module '@vue/runtime-core' {
129129
MenuLayout: typeof import('./src/components/MenuLayout.vue')['default']
130130
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
131131
MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default']
132-
NA: typeof import('naive-ui')['NA']
133132
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
134-
NCode: typeof import('naive-ui')['NCode']
133+
NCheckbox: typeof import('naive-ui')['NCheckbox']
135134
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
136135
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
136+
NDivider: typeof import('naive-ui')['NDivider']
137137
NEllipsis: typeof import('naive-ui')['NEllipsis']
138-
NFormItem: typeof import('naive-ui')['NFormItem']
139138
NH1: typeof import('naive-ui')['NH1']
140139
NH3: typeof import('naive-ui')['NH3']
141140
NIcon: typeof import('naive-ui')['NIcon']
142-
NInputNumber: typeof import('naive-ui')['NInputNumber']
143141
NLayout: typeof import('naive-ui')['NLayout']
144142
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
145143
NMenu: typeof import('naive-ui')['NMenu']
146-
NScrollbar: typeof import('naive-ui')['NScrollbar']
147-
NSpin: typeof import('naive-ui')['NSpin']
144+
NSpace: typeof import('naive-ui')['NSpace']
145+
NTable: typeof import('naive-ui')['NTable']
148146
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
149147
OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default']
150148
PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default']
@@ -154,6 +152,8 @@ declare module '@vue/runtime-core' {
154152
PhoneParserAndFormatter: typeof import('./src/tools/phone-parser-and-formatter/phone-parser-and-formatter.vue')['default']
155153
QrCodeGenerator: typeof import('./src/tools/qr-code-generator/qr-code-generator.vue')['default']
156154
RandomPortGenerator: typeof import('./src/tools/random-port-generator/random-port-generator.vue')['default']
155+
RegexMemo: typeof import('./src/tools/regex-memo/regex-memo.vue')['default']
156+
'RegexMemo.content': typeof import('./src/tools/regex-memo/regex-memo.content.md')['default']
157157
RegexTester: typeof import('./src/tools/regex-tester/regex-tester.vue')['default']
158158
ResultRow: typeof import('./src/tools/ipv4-range-expander/result-row.vue')['default']
159159
RomanNumeralConverter: typeof import('./src/tools/roman-numeral-converter/roman-numeral-converter.vue')['default']

src/tools/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { tool as safelinkDecoder } from './safelink-decoder';
1010
import { tool as xmlToJson } from './xml-to-json';
1111
import { tool as jsonToXml } from './json-to-xml';
1212
import { tool as regexTester } from './regex-tester';
13+
import { tool as regexMemo } from './regex-memo';
1314
import { tool as markdownToHtml } from './markdown-to-html';
1415
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
1516
import { tool as numeronymGenerator } from './numeronym-generator';
@@ -158,6 +159,7 @@ export const toolsByCategory: ToolCategory[] = [
158159
yamlViewer,
159160
emailNormalizer,
160161
regexTester,
162+
regexMemo,
161163
],
162164
},
163165
{

src/tools/regex-memo/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { BrandJavascript } from '@vicons/tabler';
2+
import { defineTool } from '../tool';
3+
4+
export const tool = defineTool({
5+
name: 'Regex cheatsheet',
6+
path: '/regex-memo',
7+
description: 'Javascript Regex/Regular Expression cheatsheet',
8+
keywords: ['regex', 'regular', 'expression', 'javascript', 'memo', 'cheatsheet'],
9+
component: () => import('./regex-memo.vue'),
10+
icon: BrandJavascript,
11+
createdAt: new Date('2024-09-14'),
12+
});
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
### Normal characters
2+
3+
Expression | Description
4+
:--|:--
5+
`.` or `[^\n\r]` | any character *excluding* a newline or carriage return
6+
`[A-Za-z]` | alphabet
7+
`[a-z]` | lowercase alphabet
8+
`[A-Z]` | uppercase alphabet
9+
`\d` or `[0-9]` | digit
10+
`\D` or `[^0-9]` | non-digit
11+
`_` | underscore
12+
`\w` or `[A-Za-z0-9_]` | alphabet, digit or underscore
13+
`\W` or `[^A-Za-z0-9_]` | inverse of `\w`
14+
`\S` | inverse of `\s`
15+
16+
### Whitespace characters
17+
18+
Expression | Description
19+
:--|:--
20+
` ` | space
21+
`\t` | tab
22+
`\n` | newline
23+
`\r` | carriage return
24+
`\s` | space, tab, newline or carriage return
25+
26+
### Character set
27+
28+
Expression | Description
29+
:--|:--
30+
`[xyz]` | either `x`, `y` or `z`
31+
`[^xyz]` | neither `x`, `y` nor `z`
32+
`[1-3]` | either `1`, `2` or `3`
33+
`[^1-3]` | neither `1`, `2` nor `3`
34+
35+
- Think of a character set as an `OR` operation on the single characters that are enclosed between the square brackets.
36+
- Use `^` after the opening `[` to “negate” the character set.
37+
- Within a character set, `.` means a literal period.
38+
39+
### Characters that require escaping
40+
41+
#### Outside a character set
42+
43+
Expression | Description
44+
:--|:--
45+
`\.` | period
46+
`\^` | caret
47+
`\$` | dollar sign
48+
`\|` | pipe
49+
`\\` | back slash
50+
`\/` | forward slash
51+
`\(` | opening bracket
52+
`\)` | closing bracket
53+
`\[` | opening square bracket
54+
`\]` | closing square bracket
55+
`\{` | opening curly bracket
56+
`\}` | closing curly bracket
57+
58+
#### Inside a character set
59+
60+
Expression | Description
61+
:--|:--
62+
`\\` | back slash
63+
`\]` | closing square bracket
64+
65+
- A `^` must be escaped only if it occurs immediately after the opening `[` of the character set.
66+
- A `-` must be escaped only if it occurs between two alphabets or two digits.
67+
68+
### Quantifiers
69+
70+
Expression | Description
71+
:--|:--
72+
`{2}` | exactly 2
73+
`{2,}` | at least 2
74+
`{2,7}` | at least 2 but no more than 7
75+
`*` | 0 or more
76+
`+` | 1 or more
77+
`?` | exactly 0 or 1
78+
79+
- The quantifier goes *after* the expression to be quantified.
80+
81+
### Boundaries
82+
83+
Expression | Description
84+
:--|:--
85+
`^` | start of string
86+
`$` | end of string
87+
`\b` | word boundary
88+
89+
- How word boundary matching works:
90+
- At the beginning of the string if the first character is `\w`.
91+
- Between two adjacent characters within the string, if the first character is `\w` and the second character is `\W`.
92+
- At the end of the string if the last character is `\w`.
93+
94+
### Matching
95+
96+
Expression | Description
97+
:--|:--
98+
`foo\|bar` | match either `foo` or `bar`
99+
`foo(?=bar)` | match `foo` if it’s before `bar`
100+
`foo(?!bar)` | match `foo` if it’s *not* before `bar`
101+
`(?<=bar)foo` | match `foo` if it’s after `bar`
102+
`(?<!bar)foo` | match `foo` if it’s *not* after `bar`
103+
104+
### Grouping and capturing
105+
106+
Expression | Description
107+
:--|:--
108+
`(foo)` | capturing group; match and capture `foo`
109+
`(?:foo)` | non-capturing group; match `foo` but *without* capturing `foo`
110+
`(foo)bar\1` | `\1` is a backreference to the 1st capturing group; match `foobarfoo`
111+
112+
- Capturing groups are only relevant in the following methods:
113+
- `string.match(regexp)`
114+
- `string.matchAll(regexp)`
115+
- `string.replace(regexp, callback)`
116+
- `\N` is a backreference to the `Nth` capturing group. Capturing groups are numbered starting from 1.
117+
118+
## References and tools
119+
120+
- [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions)
121+
- [RegExplained](https://leaverou.github.io/regexplained/)

src/tools/regex-memo/regex-memo.vue

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<script setup lang="ts">
2+
import { useThemeVars } from 'naive-ui';
3+
import Memo from './regex-memo.content.md';
4+
5+
const themeVars = useThemeVars();
6+
</script>
7+
8+
<template>
9+
<div>
10+
<Memo />
11+
</div>
12+
</template>
13+
14+
<style lang="less" scoped>
15+
::v-deep(pre) {
16+
margin: 0;
17+
padding: 15px 22px;
18+
background-color: v-bind('themeVars.cardColor');
19+
border-radius: 4px;
20+
overflow: auto;
21+
}
22+
::v-deep(table) {
23+
border-collapse: collapse;
24+
}
25+
::v-deep(table), ::v-deep(td), ::v-deep(th) {
26+
border: 1px solid v-bind('themeVars.textColor1');
27+
padding: 5px;
28+
}
29+
::v-deep(a) {
30+
color: v-bind('themeVars.textColor1');
31+
}
32+
</style>

src/tools/regex-tester/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ export const tool = defineTool({
88
keywords: ['regex', 'tester', 'sample', 'expression'],
99
component: () => import('./regex-tester.vue'),
1010
icon: Language,
11-
createdAt: new Date('2024-04-20'),
11+
createdAt: new Date('2024-09-14'),
1212
});

src/tools/regex-tester/regex-tester.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ watchEffect(
101101
rows="3"
102102
:validation="regexValidation"
103103
/>
104-
<n-a target="_blank" href="https://www.regular-expressions.info/javascript.html" mb-1 mt-1>
105-
See documentation on <code>regular-expressions.info</code>
106-
</n-a>
104+
<router-link target="_blank" to="/regex-memo" mb-1 mt-1>
105+
See Regular Expression Cheatsheet
106+
</router-link>
107107
<n-space>
108108
<n-checkbox v-model:checked="global">
109109
<span title="Global search">Global search. (<code>g</code>)</span>

0 commit comments

Comments
 (0)