mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-11 00:21:29 -04:00
feat: Synchronous Update
This commit is contained in:
commit
e7ccf65fe5
95 changed files with 8870 additions and 5322 deletions
13
src/tools/regex-memo/index.ts
Normal file
13
src/tools/regex-memo/index.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
import { BrandJavascript } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate as t } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: t('tools.regex-memo.title'),
|
||||
path: '/regex-memo',
|
||||
description: t('tools.regex-memo.description'),
|
||||
keywords: ['regex', 'regular', 'expression', 'javascript', 'memo', 'cheatsheet'],
|
||||
component: () => import('./regex-memo.vue'),
|
||||
icon: BrandJavascript,
|
||||
createdAt: new Date('2024-09-20'),
|
||||
});
|
4
src/tools/regex-memo/locales/en.yml
Normal file
4
src/tools/regex-memo/locales/en.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
tools:
|
||||
regex-memo:
|
||||
title: Regex cheatsheet
|
||||
description: Javascript Regex/Regular Expression cheatsheet.
|
4
src/tools/regex-memo/locales/fr.yml
Normal file
4
src/tools/regex-memo/locales/fr.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
tools:
|
||||
regex-memo:
|
||||
title: Feuille de triche Regex
|
||||
description: Feuille de triche Javascript Regex/Expression régulière.
|
4
src/tools/regex-memo/locales/zh.yml
Normal file
4
src/tools/regex-memo/locales/zh.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
tools:
|
||||
regex-memo:
|
||||
title: 正则表达式速查表
|
||||
description: Javascript 正则表达式速查表。
|
121
src/tools/regex-memo/regex-memo.content.fr.md
Normal file
121
src/tools/regex-memo/regex-memo.content.fr.md
Normal file
|
@ -0,0 +1,121 @@
|
|||
### Caractères normaux
|
||||
|
||||
Expression | Description
|
||||
:--|:--
|
||||
`.` ou `[^\n\r]` | tout caractère *sauf* un saut de ligne ou retour chariot
|
||||
`[A-Za-z]` | alphabet
|
||||
`[a-z]` | alphabet minuscule
|
||||
`[A-Z]` | alphabet majuscule
|
||||
`\d` ou `[0-9]` | chiffre
|
||||
`\D` ou `[^0-9]` | non-chiffre
|
||||
`_` | soulignement
|
||||
`\w` ou `[A-Za-z0-9_]` | alphabet, chiffre ou soulignement
|
||||
`\W` ou `[^A-Za-z0-9_]` | inverse de `\w`
|
||||
`\S` | inverse de `\s`
|
||||
|
||||
### Caractères d'espace
|
||||
|
||||
Expression | Description
|
||||
:--|:--
|
||||
` ` | espace
|
||||
`\t` | tabulation
|
||||
`\n` | saut de ligne
|
||||
`\r` | retour chariot
|
||||
`\s` | espace, tabulation, saut de ligne ou retour chariot
|
||||
|
||||
### Ensemble de caractères
|
||||
|
||||
Expression | Description
|
||||
:--|:--
|
||||
`[xyz]` | soit `x`, `y` ou `z`
|
||||
`[^xyz]` | ni `x`, ni `y`, ni `z`
|
||||
`[1-3]` | soit `1`, `2` ou `3`
|
||||
`[^1-3]` | ni `1`, ni `2`, ni `3`
|
||||
|
||||
- Pensez à un ensemble de caractères comme une opération `OU` sur les caractères simples qui sont enfermés entre crochets.
|
||||
- Utilisez `^` après le `[` d'ouverture pour "négation" de l'ensemble de caractères.
|
||||
- Dans un ensemble de caractères, `.` signifie un point littéral.
|
||||
|
||||
### Caractères nécessitant un échappement
|
||||
|
||||
#### En dehors d'un ensemble de caractères
|
||||
|
||||
Expression | Description
|
||||
:--|:--
|
||||
`\.` | point
|
||||
`\^` | accent circonflexe
|
||||
`\$` | signe dollar
|
||||
`\|` | barre verticale
|
||||
`\\` | barre oblique inverse
|
||||
`\/` | barre oblique
|
||||
`\(` | parenthèse ouvrante
|
||||
`\)` | parenthèse fermante
|
||||
`\[` | crochet ouvrant
|
||||
`\]` | crochet fermant
|
||||
`\{` | accolade ouvrante
|
||||
`\}` | accolade fermante
|
||||
|
||||
#### À l'intérieur d'un ensemble de caractères
|
||||
|
||||
Expression | Description
|
||||
:--|:--
|
||||
`\\` | barre oblique inverse
|
||||
`\]` | crochet fermant
|
||||
|
||||
- Un `^` doit être échappé uniquement s'il se produit immédiatement après le `[` d'ouverture de l'ensemble de caractères.
|
||||
- Un `-` doit être échappé uniquement s'il se produit entre deux alphabets ou deux chiffres.
|
||||
|
||||
### Quantificateurs
|
||||
|
||||
Expression | Description
|
||||
:--|:--
|
||||
`{2}` | exactement 2
|
||||
`{2,}` | au moins 2
|
||||
`{2,7}` | au moins 2 mais pas plus de 7
|
||||
`*` | 0 ou plus
|
||||
`+` | 1 ou plus
|
||||
`?` | exactement 0 ou 1
|
||||
|
||||
- Le quantificateur va *après* l'expression à quantifier.
|
||||
|
||||
### Limites
|
||||
|
||||
Expression | Description
|
||||
:--|:--
|
||||
`^` | début de chaîne
|
||||
`$` | fin de chaîne
|
||||
`\b` | limite de mot
|
||||
|
||||
- Comment fonctionne la correspondance des limites de mots :
|
||||
- Au début de la chaîne si le premier caractère est `\w`.
|
||||
- Entre deux caractères adjacents dans la chaîne, si le premier caractère est `\w` et le deuxième caractère est `\W`.
|
||||
- À la fin de la chaîne si le dernier caractère est `\w`.
|
||||
|
||||
### Correspondance
|
||||
|
||||
Expression | Description
|
||||
:--|:--
|
||||
`foo\|bar` | correspond soit à `foo` soit à `bar`
|
||||
`foo(?=bar)` | correspond à `foo` s'il est avant `bar`
|
||||
`foo(?!bar)` | correspond à `foo` s'il n'est *pas* avant `bar`
|
||||
`(?<=bar)foo` | correspond à `foo` s'il est après `bar`
|
||||
`(?<!bar)foo` | correspond à `foo` s'il n'est *pas* après `bar`
|
||||
|
||||
### Regroupement et capture
|
||||
|
||||
Expression | Description
|
||||
:--|:--
|
||||
`(foo)` | groupe de capture ; correspond et capture `foo`
|
||||
`(?:foo)` | groupe non-capturant ; correspond à `foo` mais *sans* capturer `foo`
|
||||
`(foo)bar\1` | `\1` est une référence inverse au 1er groupe de capture ; correspond à `foobarfoo`
|
||||
|
||||
- Les groupes de capture ne sont pertinents que dans les méthodes suivantes :
|
||||
- `string.match(regexp)`
|
||||
- `string.matchAll(regexp)`
|
||||
- `string.replace(regexp, callback)`
|
||||
- `\N` est une référence inverse au groupe de capture `Nth`. Les groupes de capture sont numérotés à partir de 1.
|
||||
|
||||
## Références et outils
|
||||
|
||||
- [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions)
|
||||
- [RegExplained](https://leaverou.github.io/regexplained/)
|
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/)
|
121
src/tools/regex-memo/regex-memo.content.zh.md
Normal file
121
src/tools/regex-memo/regex-memo.content.zh.md
Normal file
|
@ -0,0 +1,121 @@
|
|||
### 普通字符
|
||||
|
||||
表达式 | 描述
|
||||
:--|:--
|
||||
`.` 或 `[^\n\r]` | 任何字符 *不包括* 换行或回车
|
||||
`[A-Za-z]` | 字母
|
||||
`[a-z]` | 小写字母
|
||||
`[A-Z]` | 大写字母
|
||||
`\d` 或 `[0-9]` | 数字
|
||||
`\D` 或 `[^0-9]` | 非数字
|
||||
`_` | 下划线
|
||||
`\w` 或 `[A-Za-z0-9_]` | 字母、数字或下划线
|
||||
`\W` 或 `[^A-Za-z0-9_]` | `\w` 的反义
|
||||
`\S` | `\s` 的反义
|
||||
|
||||
### 空白字符
|
||||
|
||||
表达式 | 描述
|
||||
:--|:--
|
||||
` ` | 空格
|
||||
`\t` | 制表符
|
||||
`\n` | 换行
|
||||
`\r` | 回车
|
||||
`\s` | 空格、制表符、换行或回车
|
||||
|
||||
### 字符集
|
||||
|
||||
表达式 | 描述
|
||||
:--|:--
|
||||
`[xyz]` | `x`、`y` 或 `z` 中的任意一个
|
||||
`[^xyz]` | 既不是 `x`、`y` 也不是 `z`
|
||||
`[1-3]` | `1`、`2` 或 `3` 中的任意一个
|
||||
`[^1-3]` | 既不是 `1`、`2` 也不是 `3`
|
||||
|
||||
- 将字符集视为对方括号内单个字符的 `OR` 操作。
|
||||
- 在开括号 `[` 后使用 `^` 来“否定”字符集。
|
||||
- 在字符集中,`.` 表示字面上的句号。
|
||||
|
||||
### 需要转义的字符
|
||||
|
||||
#### 在字符集外
|
||||
|
||||
表达式 | 描述
|
||||
:--|:--
|
||||
`\.` | 句号
|
||||
`\^` | 脱字符
|
||||
`\$` | 美元符号
|
||||
`\|` | 竖线
|
||||
`\\` | 反斜杠
|
||||
`\/` | 斜线
|
||||
`\(` | 开括号
|
||||
`\)` | 闭括号
|
||||
`\[` | 开方括号
|
||||
`\]` | 闭方括号
|
||||
`\{` | 开花括号
|
||||
`\}` | 闭花括号
|
||||
|
||||
#### 在字符集内
|
||||
|
||||
表达式 | 描述
|
||||
:--|:--
|
||||
`\\` | 反斜杠
|
||||
`\]` | 闭方括号
|
||||
|
||||
- 只有当 `^` 紧接在字符集的开括号 `[` 后面时才需要转义。
|
||||
- 只有当 `-` 出现在两个字母或两个数字之间时才需要转义。
|
||||
|
||||
### 量词
|
||||
|
||||
表达式 | 描述
|
||||
:--|:--
|
||||
`{2}` | 精确 2 次
|
||||
`{2,}` | 至少 2 次
|
||||
`{2,7}` | 至少 2 次但不超过 7 次
|
||||
`*` | 0 次或更多
|
||||
`+` | 1 次或更多
|
||||
`?` | 精确 0 次或 1 次
|
||||
|
||||
- 量词位于待量词化的表达式 *之后*。
|
||||
|
||||
### 边界
|
||||
|
||||
表达式 | 描述
|
||||
:--|:--
|
||||
`^` | 字符串开始
|
||||
`$` | 字符串结束
|
||||
`\b` | 单词边界
|
||||
|
||||
- 单词边界匹配的工作原理:
|
||||
- 在字符串开始时,如果第一个字符是 `\w`。
|
||||
- 在字符串中两个相邻字符之间,如果第一个字符是 `\w`,而第二个字符是 `\W`。
|
||||
- 在字符串结束时,如果最后一个字符是 `\w`。
|
||||
|
||||
### 匹配
|
||||
|
||||
表达式 | 描述
|
||||
:--|:--
|
||||
`foo\|bar` | 匹配 `foo` 或 `bar`
|
||||
`foo(?=bar)` | 如果 `foo` 在 `bar` 前面则匹配 `foo`
|
||||
`foo(?!bar)` | 如果 `foo` *不* 在 `bar` 前面则匹配 `foo`
|
||||
`(?<=bar)foo` | 如果 `foo` 在 `bar` 后面则匹配 `foo`
|
||||
`(?<!bar)foo` | 如果 `foo` *不* 在 `bar` 后面则匹配 `foo`
|
||||
|
||||
### 分组与捕获
|
||||
|
||||
表达式 | 描述
|
||||
:--|:--
|
||||
`(foo)` | 捕获组;匹配并捕获 `foo`
|
||||
`(?:foo)` | 非捕获组;匹配 `foo` 但 *不* 捕获 `foo`
|
||||
`(foo)bar\1` | `\1` 是对第 1 个捕获组的回参考;匹配 `foobarfoo`
|
||||
|
||||
- 捕获组仅在以下方法中相关:
|
||||
- `string.match(regexp)`
|
||||
- `string.matchAll(regexp)`
|
||||
- `string.replace(regexp, callback)`
|
||||
- `\N` 是对第 `N` 个捕获组的回参考。捕获组的编号从 1 开始。
|
||||
|
||||
## 参考文献和工具
|
||||
|
||||
- [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions)
|
||||
- [RegExplained](https://leaverou.github.io/regexplained/)
|
37
src/tools/regex-memo/regex-memo.vue
Normal file
37
src/tools/regex-memo/regex-memo.vue
Normal file
|
@ -0,0 +1,37 @@
|
|||
<script setup lang="ts">
|
||||
import { useThemeVars } from 'naive-ui';
|
||||
import Memo from './regex-memo.content.md';
|
||||
import MemoZH from './regex-memo.content.zh.md';
|
||||
import MemoFR from './regex-memo.content.fr.md';
|
||||
|
||||
const themeVars = useThemeVars();
|
||||
const { locale } = useI18n();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<MemoZH v-if="locale === 'zh'" />
|
||||
<MemoFR v-else-if="locale === 'fr'" />
|
||||
<Memo v-else />
|
||||
</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>
|
Loading…
Add table
Add a link
Reference in a new issue