feat(new tool): added Regex Cheatsheet
This commit is contained in:
		
							parent
							
								
									f0a092f95a
								
							
						
					
					
						commit
						e2a1748fa9
					
				
							
								
								
									
										12
									
								
								components.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										12
									
								
								components.d.ts
									
									
									
									
										vendored
									
									
								
							| @ -129,22 +129,20 @@ declare module '@vue/runtime-core' { | |||||||
|     MenuLayout: typeof import('./src/components/MenuLayout.vue')['default'] |     MenuLayout: typeof import('./src/components/MenuLayout.vue')['default'] | ||||||
|     MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default'] |     MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default'] | ||||||
|     MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default'] |     MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default'] | ||||||
|     NA: typeof import('naive-ui')['NA'] |  | ||||||
|     NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default'] |     NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default'] | ||||||
|     NCode: typeof import('naive-ui')['NCode'] |     NCheckbox: typeof import('naive-ui')['NCheckbox'] | ||||||
|     NCollapseTransition: typeof import('naive-ui')['NCollapseTransition'] |     NCollapseTransition: typeof import('naive-ui')['NCollapseTransition'] | ||||||
|     NConfigProvider: typeof import('naive-ui')['NConfigProvider'] |     NConfigProvider: typeof import('naive-ui')['NConfigProvider'] | ||||||
|  |     NDivider: typeof import('naive-ui')['NDivider'] | ||||||
|     NEllipsis: typeof import('naive-ui')['NEllipsis'] |     NEllipsis: typeof import('naive-ui')['NEllipsis'] | ||||||
|     NFormItem: typeof import('naive-ui')['NFormItem'] |  | ||||||
|     NH1: typeof import('naive-ui')['NH1'] |     NH1: typeof import('naive-ui')['NH1'] | ||||||
|     NH3: typeof import('naive-ui')['NH3'] |     NH3: typeof import('naive-ui')['NH3'] | ||||||
|     NIcon: typeof import('naive-ui')['NIcon'] |     NIcon: typeof import('naive-ui')['NIcon'] | ||||||
|     NInputNumber: typeof import('naive-ui')['NInputNumber'] |  | ||||||
|     NLayout: typeof import('naive-ui')['NLayout'] |     NLayout: typeof import('naive-ui')['NLayout'] | ||||||
|     NLayoutSider: typeof import('naive-ui')['NLayoutSider'] |     NLayoutSider: typeof import('naive-ui')['NLayoutSider'] | ||||||
|     NMenu: typeof import('naive-ui')['NMenu'] |     NMenu: typeof import('naive-ui')['NMenu'] | ||||||
|     NScrollbar: typeof import('naive-ui')['NScrollbar'] |     NSpace: typeof import('naive-ui')['NSpace'] | ||||||
|     NSpin: typeof import('naive-ui')['NSpin'] |     NTable: typeof import('naive-ui')['NTable'] | ||||||
|     NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default'] |     NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default'] | ||||||
|     OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default'] |     OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default'] | ||||||
|     PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default'] |     PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default'] | ||||||
| @ -154,6 +152,8 @@ declare module '@vue/runtime-core' { | |||||||
|     PhoneParserAndFormatter: typeof import('./src/tools/phone-parser-and-formatter/phone-parser-and-formatter.vue')['default'] |     PhoneParserAndFormatter: typeof import('./src/tools/phone-parser-and-formatter/phone-parser-and-formatter.vue')['default'] | ||||||
|     QrCodeGenerator: typeof import('./src/tools/qr-code-generator/qr-code-generator.vue')['default'] |     QrCodeGenerator: typeof import('./src/tools/qr-code-generator/qr-code-generator.vue')['default'] | ||||||
|     RandomPortGenerator: typeof import('./src/tools/random-port-generator/random-port-generator.vue')['default'] |     RandomPortGenerator: typeof import('./src/tools/random-port-generator/random-port-generator.vue')['default'] | ||||||
|  |     RegexMemo: typeof import('./src/tools/regex-memo/regex-memo.vue')['default'] | ||||||
|  |     'RegexMemo.content': typeof import('./src/tools/regex-memo/regex-memo.content.md')['default'] | ||||||
|     RegexTester: typeof import('./src/tools/regex-tester/regex-tester.vue')['default'] |     RegexTester: typeof import('./src/tools/regex-tester/regex-tester.vue')['default'] | ||||||
|     ResultRow: typeof import('./src/tools/ipv4-range-expander/result-row.vue')['default'] |     ResultRow: typeof import('./src/tools/ipv4-range-expander/result-row.vue')['default'] | ||||||
|     RomanNumeralConverter: typeof import('./src/tools/roman-numeral-converter/roman-numeral-converter.vue')['default'] |     RomanNumeralConverter: typeof import('./src/tools/roman-numeral-converter/roman-numeral-converter.vue')['default'] | ||||||
|  | |||||||
| @ -10,6 +10,7 @@ import { tool as safelinkDecoder } from './safelink-decoder'; | |||||||
| import { tool as xmlToJson } from './xml-to-json'; | import { tool as xmlToJson } from './xml-to-json'; | ||||||
| import { tool as jsonToXml } from './json-to-xml'; | import { tool as jsonToXml } from './json-to-xml'; | ||||||
| import { tool as regexTester } from './regex-tester'; | import { tool as regexTester } from './regex-tester'; | ||||||
|  | import { tool as regexMemo } from './regex-memo'; | ||||||
| import { tool as markdownToHtml } from './markdown-to-html'; | import { tool as markdownToHtml } from './markdown-to-html'; | ||||||
| import { tool as pdfSignatureChecker } from './pdf-signature-checker'; | import { tool as pdfSignatureChecker } from './pdf-signature-checker'; | ||||||
| import { tool as numeronymGenerator } from './numeronym-generator'; | import { tool as numeronymGenerator } from './numeronym-generator'; | ||||||
| @ -158,6 +159,7 @@ export const toolsByCategory: ToolCategory[] = [ | |||||||
|       yamlViewer, |       yamlViewer, | ||||||
|       emailNormalizer, |       emailNormalizer, | ||||||
|       regexTester, |       regexTester, | ||||||
|  |       regexMemo, | ||||||
|     ], |     ], | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|  | |||||||
							
								
								
									
										12
									
								
								src/tools/regex-memo/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/tools/regex-memo/index.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,12 @@ | |||||||
|  | import { BrandJavascript } from '@vicons/tabler'; | ||||||
|  | import { defineTool } from '../tool'; | ||||||
|  | 
 | ||||||
|  | export const tool = defineTool({ | ||||||
|  |   name: 'Regex cheatsheet', | ||||||
|  |   path: '/regex-memo', | ||||||
|  |   description: 'Javascript Regex/Regular Expression cheatsheet', | ||||||
|  |   keywords: ['regex', 'regular', 'expression', 'javascript', 'memo', 'cheatsheet'], | ||||||
|  |   component: () => import('./regex-memo.vue'), | ||||||
|  |   icon: BrandJavascript, | ||||||
|  |   createdAt: new Date('2024-09-14'), | ||||||
|  | }); | ||||||
							
								
								
									
										121
									
								
								src/tools/regex-memo/regex-memo.content.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										121
									
								
								src/tools/regex-memo/regex-memo.content.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,121 @@ | |||||||
|  | ### Normal characters | ||||||
|  | 
 | ||||||
|  | Expression | Description | ||||||
|  | :--|:-- | ||||||
|  | `.` or `[^\n\r]` | any character *excluding* a newline or carriage return | ||||||
|  | `[A-Za-z]` | alphabet | ||||||
|  | `[a-z]` | lowercase alphabet | ||||||
|  | `[A-Z]` | uppercase alphabet | ||||||
|  | `\d` or `[0-9]` | digit | ||||||
|  | `\D` or `[^0-9]` | non-digit | ||||||
|  | `_` | underscore | ||||||
|  | `\w` or `[A-Za-z0-9_]` | alphabet, digit or underscore | ||||||
|  | `\W` or `[^A-Za-z0-9_]` | inverse of `\w` | ||||||
|  | `\S` | inverse of `\s` | ||||||
|  | 
 | ||||||
|  | ### Whitespace characters | ||||||
|  | 
 | ||||||
|  | Expression | Description | ||||||
|  | :--|:-- | ||||||
|  | ` ` | space | ||||||
|  | `\t` | tab | ||||||
|  | `\n` | newline | ||||||
|  | `\r` | carriage return | ||||||
|  | `\s` | space, tab, newline or carriage return | ||||||
|  | 
 | ||||||
|  | ### Character set | ||||||
|  | 
 | ||||||
|  | Expression | Description | ||||||
|  | :--|:-- | ||||||
|  | `[xyz]` | either `x`, `y` or `z` | ||||||
|  | `[^xyz]` | neither `x`, `y` nor `z` | ||||||
|  | `[1-3]` | either `1`, `2` or `3` | ||||||
|  | `[^1-3]` | neither `1`, `2` nor `3` | ||||||
|  | 
 | ||||||
|  | - Think of a character set as an `OR` operation on the single characters that are enclosed between the square brackets. | ||||||
|  | - Use `^` after the opening `[` to “negate” the character set. | ||||||
|  | - Within a character set, `.` means a literal period. | ||||||
|  | 
 | ||||||
|  | ### Characters that require escaping | ||||||
|  | 
 | ||||||
|  | #### Outside a character set | ||||||
|  | 
 | ||||||
|  | Expression | Description | ||||||
|  | :--|:-- | ||||||
|  | `\.` | period | ||||||
|  | `\^` | caret | ||||||
|  | `\$` | dollar sign | ||||||
|  | `\|` | pipe | ||||||
|  | `\\` | back slash | ||||||
|  | `\/` | forward slash | ||||||
|  | `\(` | opening bracket | ||||||
|  | `\)` | closing bracket | ||||||
|  | `\[` | opening square bracket | ||||||
|  | `\]` | closing square bracket | ||||||
|  | `\{` | opening curly bracket | ||||||
|  | `\}` | closing curly bracket | ||||||
|  | 
 | ||||||
|  | #### Inside a character set | ||||||
|  | 
 | ||||||
|  | Expression | Description | ||||||
|  | :--|:-- | ||||||
|  | `\\` | back slash | ||||||
|  | `\]` | closing square bracket | ||||||
|  | 
 | ||||||
|  | - A `^` must be escaped only if it occurs immediately after the opening `[` of the character set. | ||||||
|  | - A `-` must be escaped only if it occurs between two alphabets or two digits. | ||||||
|  | 
 | ||||||
|  | ### Quantifiers | ||||||
|  | 
 | ||||||
|  | Expression | Description | ||||||
|  | :--|:-- | ||||||
|  | `{2}` | exactly 2 | ||||||
|  | `{2,}` | at least 2 | ||||||
|  | `{2,7}` | at least 2 but no more than 7 | ||||||
|  | `*` | 0 or more | ||||||
|  | `+` | 1 or more | ||||||
|  | `?` | exactly 0 or 1 | ||||||
|  | 
 | ||||||
|  | - The quantifier goes *after* the expression to be quantified. | ||||||
|  | 
 | ||||||
|  | ### Boundaries | ||||||
|  | 
 | ||||||
|  | Expression | Description | ||||||
|  | :--|:-- | ||||||
|  | `^` | start of string | ||||||
|  | `$` | end of string | ||||||
|  | `\b` | word boundary | ||||||
|  | 
 | ||||||
|  | - How word boundary matching works: | ||||||
|  |     - At the beginning of the string if the first character is `\w`. | ||||||
|  |     - Between two adjacent characters within the string, if the first character is `\w` and the second character is `\W`. | ||||||
|  |     - At the end of the string if the last character is `\w`. | ||||||
|  | 
 | ||||||
|  | ### Matching | ||||||
|  | 
 | ||||||
|  | Expression | Description | ||||||
|  | :--|:-- | ||||||
|  | `foo\|bar` | match either `foo` or `bar` | ||||||
|  | `foo(?=bar)` | match `foo` if it’s before `bar` | ||||||
|  | `foo(?!bar)` | match `foo` if it’s *not* before `bar` | ||||||
|  | `(?<=bar)foo` | match `foo` if it’s after `bar` | ||||||
|  | `(?<!bar)foo` | match `foo` if it’s *not* after `bar` | ||||||
|  | 
 | ||||||
|  | ### Grouping and capturing | ||||||
|  | 
 | ||||||
|  | Expression | Description | ||||||
|  | :--|:-- | ||||||
|  | `(foo)` | capturing group; match and capture `foo` | ||||||
|  | `(?:foo)` | non-capturing group; match `foo` but *without* capturing `foo` | ||||||
|  | `(foo)bar\1` | `\1` is a backreference to the 1st capturing group; match `foobarfoo` | ||||||
|  | 
 | ||||||
|  | - Capturing groups are only relevant in the following methods: | ||||||
|  |     - `string.match(regexp)` | ||||||
|  |     - `string.matchAll(regexp)` | ||||||
|  |     - `string.replace(regexp, callback)` | ||||||
|  | - `\N` is a backreference to the `Nth` capturing group. Capturing groups are numbered starting from 1. | ||||||
|  | 
 | ||||||
|  | ## References and tools | ||||||
|  | 
 | ||||||
|  | - [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions) | ||||||
|  | - [RegExplained](https://leaverou.github.io/regexplained/) | ||||||
							
								
								
									
										32
									
								
								src/tools/regex-memo/regex-memo.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								src/tools/regex-memo/regex-memo.vue
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,32 @@ | |||||||
|  | <script setup lang="ts"> | ||||||
|  | import { useThemeVars } from 'naive-ui'; | ||||||
|  | import Memo from './regex-memo.content.md'; | ||||||
|  | 
 | ||||||
|  | const themeVars = useThemeVars(); | ||||||
|  | </script> | ||||||
|  | 
 | ||||||
|  | <template> | ||||||
|  |   <div> | ||||||
|  |     <Memo /> | ||||||
|  |   </div> | ||||||
|  | </template> | ||||||
|  | 
 | ||||||
|  | <style lang="less" scoped> | ||||||
|  | ::v-deep(pre) { | ||||||
|  |   margin: 0; | ||||||
|  |   padding: 15px 22px; | ||||||
|  |   background-color: v-bind('themeVars.cardColor'); | ||||||
|  |   border-radius: 4px; | ||||||
|  |   overflow: auto; | ||||||
|  | } | ||||||
|  | ::v-deep(table) { | ||||||
|  |   border-collapse: collapse; | ||||||
|  | } | ||||||
|  | ::v-deep(table), ::v-deep(td), ::v-deep(th) { | ||||||
|  |   border: 1px solid v-bind('themeVars.textColor1'); | ||||||
|  |   padding: 5px; | ||||||
|  | } | ||||||
|  | ::v-deep(a) { | ||||||
|  |   color: v-bind('themeVars.textColor1'); | ||||||
|  | } | ||||||
|  | </style> | ||||||
| @ -8,5 +8,5 @@ export const tool = defineTool({ | |||||||
|   keywords: ['regex', 'tester', 'sample', 'expression'], |   keywords: ['regex', 'tester', 'sample', 'expression'], | ||||||
|   component: () => import('./regex-tester.vue'), |   component: () => import('./regex-tester.vue'), | ||||||
|   icon: Language, |   icon: Language, | ||||||
|   createdAt: new Date('2024-04-20'), |   createdAt: new Date('2024-09-14'), | ||||||
| }); | }); | ||||||
|  | |||||||
| @ -101,9 +101,9 @@ watchEffect( | |||||||
|         rows="3" |         rows="3" | ||||||
|         :validation="regexValidation" |         :validation="regexValidation" | ||||||
|       /> |       /> | ||||||
|       <n-a target="_blank" href="https://www.regular-expressions.info/javascript.html" mb-1 mt-1> |       <router-link target="_blank" to="/regex-memo" mb-1 mt-1> | ||||||
|         See documentation on <code>regular-expressions.info</code> |         See Regular Expression Cheatsheet | ||||||
|       </n-a> |       </router-link> | ||||||
|       <n-space> |       <n-space> | ||||||
|         <n-checkbox v-model:checked="global"> |         <n-checkbox v-model:checked="global"> | ||||||
|           <span title="Global search">Global search. (<code>g</code>)</span> |           <span title="Global search">Global search. (<code>g</code>)</span> | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user