Skip to content

Commit

Permalink
Merge pull request #175 from majvax/regex
Browse files Browse the repository at this point in the history
Added support for regex snippets
  • Loading branch information
Mathys-Gasnier authored Jan 4, 2025
2 parents fd8d475 + 124a614 commit de6a842
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 0 deletions.
4 changes: 4 additions & 0 deletions public/consolidated/_index.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
"lang": "PYTHON",
"icon": "/icons/python.svg"
},
{
"lang": "REGEX",
"icon": "/icons/regex.svg"
},
{
"lang": "RUST",
"icon": "/icons/rust.svg"
Expand Down
17 changes: 17 additions & 0 deletions public/consolidated/cpp.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@
}
]
},
{
"categoryName": "Debuging",
"snippets": [
{
"title": "Vector Print",
"description": "Overloads the << operator to print the contents of a vector just like in python.",
"author": "Mohamed-faaris",
"tags": [
"printing",
"debuging",
"vector"
],
"contributors": [],
"code": "#include <iostream> \n#include <vector> \n\ntemplate <typename T>\nstd::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {\n os << \"[\"; \n for (size_t i = 0; i < vec.size(); ++i) {\n os << vec[i]; // Print each vector element\n if (i != vec.size() - 1) {\n os << \", \"; // Add separator\n }\n }\n os << \"]\"; \n return os; // Return the stream\n}\n\n// Usage:\nstd::vector<int> numbers = {1, 2, 3, 4, 5};\nstd::cout << numbers << std::endl; // Outputs: [1, 2, 3, 4, 5]\n\n"
}
]
},
{
"categoryName": "Math And Numbers",
"snippets": [
Expand Down
74 changes: 74 additions & 0 deletions public/consolidated/regex.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[
{
"categoryName": "Miscellaneous",
"snippets": [
{
"title": "Hexadecimal Color",
"description": "Matches hex color codes",
"author": "majvax",
"tags": [
"color",
"hexadecimal"
],
"contributors": [],
"code": "^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$\n\n\n-> Usage:\n#FFF1 ✗\n#FFF ✓\n#FFF000 ✓\n"
},
{
"title": "IPv4",
"description": "Matches IPv4 address",
"author": "majvax",
"tags": [
"ipv4",
"networking"
],
"contributors": [],
"code": "^((25[0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})\\.){3}(25[0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})$\n\n\n-> Usage:\n123.300.0.101 ✗\n127.0.0.1 ✓\n192.168.0.1 ✓\n"
},
{
"title": "Unintentional Duplication",
"description": "Matches duplicated word in a text.",
"author": "majvax",
"tags": [
"duplication"
],
"contributors": [],
"code": "\\b(\\w+)\\s+\\1\\b\n\n\n-> Usage:\nI need to finish this task ✗\nI need to to finish this task ✓\n"
},
{
"title": "Whitespace Trimmer",
"description": "Matches leading and/or trailing whitespace.",
"author": "majvax",
"tags": [
"trim"
],
"contributors": [],
"code": "^\\s+|\\s+$\n\n\n-> Usage:\n(don't account for the quotation marks, it just to visualize whitespace)\n\"Hello World\"\n\" Hello World\"\n\"Hello World \"\n\" Hello World \"\n"
}
]
},
{
"categoryName": "Validation pattern",
"snippets": [
{
"title": "Email Address",
"description": "Match any email address",
"author": "majvax",
"tags": [
"email"
],
"contributors": [],
"code": "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$\n\n-> Usage:\n[email protected]\n[email protected]\n"
},
{
"title": "Strong Password",
"description": "Match password with at least 12 characters, one uppercased letter, one number, and one special character.",
"author": "majvax",
"tags": [
"password"
],
"contributors": [],
"code": "^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d)(?=.*[@$!%*?&])[A-Za-z\\d@$!%*?&]{12,}$\n\n-> Usage:\nlongpassword ✗\nlongpassw0rd ✗\nlongp@ssw0rd ✗\nLongp@ssw0rd ✓\n"
}
]
}
]
6 changes: 6 additions & 0 deletions public/icons/regex.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions snippets/regex/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions snippets/regex/miscellaneous/hexadecimal-color.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
Title: Hexadecimal Color
Description: Matches hex color codes
Author: majvax
Tags: color,hexadecimal
---


```regex
^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$
-> Usage:
#FFF1 ✗
#FFF ✓
#FFF000 ✓
```
17 changes: 17 additions & 0 deletions snippets/regex/miscellaneous/ipv4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
Title: IPv4
Description: Matches IPv4 address
Author: majvax
Tags: ipv4,networking
---


```regex
^((25[0-5]|2[0-4]\d|1\d{2}|\d{1,2})\.){3}(25[0-5]|2[0-4]\d|1\d{2}|\d{1,2})$
-> Usage:
123.300.0.101 ✗
127.0.0.1 ✓
192.168.0.1 ✓
```
16 changes: 16 additions & 0 deletions snippets/regex/miscellaneous/unintentional-duplication.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
Title: Unintentional Duplication
Description: Matches duplicated word in a text.
Author: majvax
Tags: duplication
---


```regex
\b(\w+)\s+\1\b
-> Usage:
I need to finish this task ✗
I need to to finish this task ✓
```
19 changes: 19 additions & 0 deletions snippets/regex/miscellaneous/whitespace-trimmer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
Title: Whitespace Trimmer
Description: Matches leading and/or trailing whitespace.
Author: majvax
Tags: trim
---


```regex
^\s+|\s+$
-> Usage:
(don't account for the quotation marks, it just to visualize whitespace)
"Hello World" ✗
" Hello World" ✓
"Hello World " ✓
" Hello World " ✓
```
15 changes: 15 additions & 0 deletions snippets/regex/validation pattern/email-address.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
Title: Email Address
Description: Match any email address
Author: majvax
Tags: email
---


```regex
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
-> Usage:
[email protected]
[email protected]
```
17 changes: 17 additions & 0 deletions snippets/regex/validation pattern/strong-password.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
Title: Strong Password
Description: Match password with at least 12 characters, one uppercased letter, one number, and one special character.
Author: majvax
Tags: password
---


```regex
^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{12,}$
-> Usage:
longpassword ✗
longpassw0rd ✗
longp@ssw0rd ✗
Longp@ssw0rd ✓
```

0 comments on commit de6a842

Please sign in to comment.