@hybridlabor-api/aos 4.8.0 → 4.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/agents.md +1 -1
- package/.agents/nodes.json +1 -1
- package/.agents/vendor-manifest.json +23 -1
- package/.claude/agents/godmode-media-eventtech.md +1 -1
- package/.claude/hooks/conventional-commits.mjs +125 -0
- package/.claude/hooks/env-file-protection.mjs +105 -0
- package/.claude/hooks/go-gate.mjs +101 -81
- package/.claude/settings.json +13 -0
- package/.opencode/agents/godmode-media-eventtech.md +1 -1
- package/.opencode/plugins/bdb-aos.js +31 -4
- package/README.de.md +1 -1
- package/README.md +1 -1
- package/README.pt.md +1 -1
- package/THIRD_PARTY_NOTICES.md +88 -0
- package/docs/skills_table.md +1 -1
- package/installer.js +174 -46
- package/package.json +6 -2
- package/packages/aos-cli/README.md +80 -0
- package/packages/aos-cli/bin/aos-cli.mjs +134 -0
- package/packages/aos-cli/core-skills.json +12 -0
- package/packages/aos-cli/extensions/aos.ts +321 -0
- package/packages/aos-cli/package-lock.json +1923 -0
- package/packages/aos-cli/package.json +29 -0
- package/packages/aos-cli/scripts/check-theme.mjs +63 -0
- package/packages/aos-cli/themes/aos.json +97 -0
- package/scripts/build-plugin-manifest.mjs +131 -0
- package/scripts/validate-skills.mjs +81 -6
- package/skills/basic/ao-orchestrator/SKILL.md +116 -0
- package/skills/global_config/agenttrail/SKILL.md +6 -1
- package/skills/global_config/ask-tim/SKILL.md +4 -4
- package/skills/global_config/bash-script-generator/SKILL.md +201 -0
- package/skills/global_config/bash-script-generator/assets/templates/standard-template.sh +96 -0
- package/skills/global_config/bash-script-generator/docs/bash-scripting-guide.md +729 -0
- package/skills/global_config/bash-script-generator/docs/generation-best-practices.md +193 -0
- package/skills/global_config/bash-script-generator/docs/script-patterns.md +566 -0
- package/skills/global_config/bash-script-generator/docs/text-processing-guide.md +437 -0
- package/skills/global_config/bash-script-generator/examples/log-analyzer.sh +92 -0
- package/skills/global_config/bash-script-generator/scripts/generate_script_template.sh +123 -0
- package/skills/global_config/bash-script-generator/scripts/run_ci_checks.sh +172 -0
- package/skills/global_config/bash-script-generator/scripts/test_generator.sh +413 -0
- package/skills/global_config/bash-script-validator/SKILL.md +249 -0
- package/skills/global_config/bash-script-validator/docs/awk-reference.md +449 -0
- package/skills/global_config/bash-script-validator/docs/bash-reference.md +468 -0
- package/skills/global_config/bash-script-validator/docs/common-mistakes.md +623 -0
- package/skills/global_config/bash-script-validator/docs/grep-reference.md +395 -0
- package/skills/global_config/bash-script-validator/docs/regex-reference.md +391 -0
- package/skills/global_config/bash-script-validator/docs/sed-reference.md +454 -0
- package/skills/global_config/bash-script-validator/docs/shell-reference.md +463 -0
- package/skills/global_config/bash-script-validator/docs/shellcheck-reference.md +399 -0
- package/skills/global_config/bash-script-validator/examples/bad-bash.sh +55 -0
- package/skills/global_config/bash-script-validator/examples/bad-shell.sh +54 -0
- package/skills/global_config/bash-script-validator/examples/good-bash.sh +71 -0
- package/skills/global_config/bash-script-validator/examples/good-shell.sh +69 -0
- package/skills/global_config/bash-script-validator/scripts/run_ci_checks.sh +23 -0
- package/skills/global_config/bash-script-validator/scripts/shellcheck_wrapper.sh +174 -0
- package/skills/global_config/bash-script-validator/scripts/test_validate.sh +446 -0
- package/skills/global_config/bash-script-validator/scripts/validate.sh +512 -0
- package/skills/global_config/ci-pipeline/SKILL.md +135 -0
- package/skills/global_config/dispatching-parallel-agents/SKILL.md +170 -0
- package/skills/global_config/dockerfile-generator/SKILL.md +1038 -0
- package/skills/global_config/dockerfile-generator/examples/example.dockerignore +95 -0
- package/skills/global_config/dockerfile-generator/examples/golang-distroless.Dockerfile +34 -0
- package/skills/global_config/dockerfile-generator/examples/java-springboot.Dockerfile +45 -0
- package/skills/global_config/dockerfile-generator/examples/nextjs-production.Dockerfile +49 -0
- package/skills/global_config/dockerfile-generator/examples/nodejs-multistage.Dockerfile +55 -0
- package/skills/global_config/dockerfile-generator/examples/python-fastapi.Dockerfile +48 -0
- package/skills/global_config/dockerfile-generator/references/language_specific_guides.md +510 -0
- package/skills/global_config/dockerfile-generator/references/multistage_builds.md +570 -0
- package/skills/global_config/dockerfile-generator/references/optimization_patterns.md +492 -0
- package/skills/global_config/dockerfile-generator/references/security_best_practices.md +375 -0
- package/skills/global_config/dockerfile-generator/scripts/generate_dockerignore.sh +199 -0
- package/skills/global_config/dockerfile-generator/scripts/generate_golang.sh +172 -0
- package/skills/global_config/dockerfile-generator/scripts/generate_java.sh +185 -0
- package/skills/global_config/dockerfile-generator/scripts/generate_nodejs.sh +279 -0
- package/skills/global_config/dockerfile-generator/scripts/generate_python.sh +218 -0
- package/skills/global_config/dockerfile-generator/scripts/test_generator.sh +210 -0
- package/skills/global_config/dockerfile-validator/SKILL.md +300 -0
- package/skills/global_config/dockerfile-validator/examples/.dockerignore.example +34 -0
- package/skills/global_config/dockerfile-validator/examples/bad-example.Dockerfile +37 -0
- package/skills/global_config/dockerfile-validator/examples/golang-distroless.Dockerfile +50 -0
- package/skills/global_config/dockerfile-validator/examples/good-example.Dockerfile +52 -0
- package/skills/global_config/dockerfile-validator/examples/python-optimized.Dockerfile +53 -0
- package/skills/global_config/dockerfile-validator/examples/security-issues.Dockerfile +42 -0
- package/skills/global_config/dockerfile-validator/references/docker_best_practices.md +348 -0
- package/skills/global_config/dockerfile-validator/references/optimization_guide.md +473 -0
- package/skills/global_config/dockerfile-validator/references/security_checklist.md +208 -0
- package/skills/global_config/dockerfile-validator/scripts/dockerfile-validate.sh +699 -0
- package/skills/global_config/dockerfile-validator/scripts/test_validate.sh +35 -0
- package/skills/global_config/dockerfile-validator/tests/fixtures/copy-before-yarn-lock-read.Dockerfile +6 -0
- package/skills/global_config/dockerfile-validator/tests/fixtures/copy-before-yarn.Dockerfile +6 -0
- package/skills/global_config/dockerfile-validator/tests/fixtures/from-platform-nonroot.Dockerfile +7 -0
- package/skills/global_config/dockerfile-validator/tests/test_regression.sh +164 -0
- package/skills/global_config/finishing-a-development-branch/SKILL.md +228 -0
- package/skills/global_config/github-actions-generator/SKILL.md +353 -0
- package/skills/global_config/github-actions-generator/assets/templates/action/composite/action.yml +82 -0
- package/skills/global_config/github-actions-generator/assets/templates/action/docker/Dockerfile +25 -0
- package/skills/global_config/github-actions-generator/assets/templates/action/docker/action.yml +42 -0
- package/skills/global_config/github-actions-generator/assets/templates/action/docker/entrypoint.sh +27 -0
- package/skills/global_config/github-actions-generator/assets/templates/action/javascript/action.yml +33 -0
- package/skills/global_config/github-actions-generator/assets/templates/action/javascript/index.js +50 -0
- package/skills/global_config/github-actions-generator/assets/templates/action/javascript/package.json +27 -0
- package/skills/global_config/github-actions-generator/assets/templates/workflow/basic_workflow.yml +242 -0
- package/skills/global_config/github-actions-generator/assets/templates/workflow/reusable_workflow.yml +106 -0
- package/skills/global_config/github-actions-generator/examples/README.md +147 -0
- package/skills/global_config/github-actions-generator/examples/actions/setup-node-cached/action.yml +93 -0
- package/skills/global_config/github-actions-generator/examples/caching/docker-buildkit.yml +256 -0
- package/skills/global_config/github-actions-generator/examples/security/dependency-review.yml +62 -0
- package/skills/global_config/github-actions-generator/examples/security/sbom-attestation.yml +119 -0
- package/skills/global_config/github-actions-generator/examples/triggers/chatops-commands.yml +475 -0
- package/skills/global_config/github-actions-generator/examples/triggers/repository-dispatch.yml +418 -0
- package/skills/global_config/github-actions-generator/examples/triggers/workflow-orchestration.yml +404 -0
- package/skills/global_config/github-actions-generator/examples/workflows/docker-build-push.yml +68 -0
- package/skills/global_config/github-actions-generator/examples/workflows/go-ci.yml +161 -0
- package/skills/global_config/github-actions-generator/examples/workflows/monorepo-ci.yml +340 -0
- package/skills/global_config/github-actions-generator/examples/workflows/multi-environment-deploy.yml +406 -0
- package/skills/global_config/github-actions-generator/examples/workflows/nodejs-ci.yml +122 -0
- package/skills/global_config/github-actions-generator/examples/workflows/python-ci.yml +157 -0
- package/skills/global_config/github-actions-generator/examples/workflows/scheduled-tasks.yml +376 -0
- package/skills/global_config/github-actions-generator/references/advanced-triggers.md +917 -0
- package/skills/global_config/github-actions-generator/references/best-practices.md +755 -0
- package/skills/global_config/github-actions-generator/references/common-actions.md +715 -0
- package/skills/global_config/github-actions-generator/references/custom-actions.md +320 -0
- package/skills/global_config/github-actions-generator/references/expressions-and-contexts.md +688 -0
- package/skills/global_config/github-actions-generator/references/modern-features.md +421 -0
- package/skills/global_config/github-actions-generator/scripts/test_generator.sh +344 -0
- package/skills/global_config/github-actions-templates/SKILL.md +7 -0
- package/skills/global_config/github-actions-validator/SKILL.md +576 -0
- package/skills/global_config/github-actions-validator/examples/README.md +88 -0
- package/skills/global_config/github-actions-validator/examples/outdated-versions.yml +76 -0
- package/skills/global_config/github-actions-validator/examples/valid-ci.yml +79 -0
- package/skills/global_config/github-actions-validator/examples/with-errors.yml +47 -0
- package/skills/global_config/github-actions-validator/references/act_usage.md +233 -0
- package/skills/global_config/github-actions-validator/references/action_versions.md +122 -0
- package/skills/global_config/github-actions-validator/references/actionlint_usage.md +343 -0
- package/skills/global_config/github-actions-validator/references/common_errors.md +512 -0
- package/skills/global_config/github-actions-validator/references/modern_features.md +384 -0
- package/skills/global_config/github-actions-validator/references/runners.md +317 -0
- package/skills/global_config/github-actions-validator/scripts/install_tools.sh +113 -0
- package/skills/global_config/github-actions-validator/scripts/validate_workflow.sh +910 -0
- package/skills/global_config/github-actions-validator/tests/test_validate_workflow.sh +237 -0
- package/skills/global_config/makefile-generator/SKILL.md +614 -0
- package/skills/global_config/makefile-generator/assets/templates/.gitkeep +1 -0
- package/skills/global_config/makefile-generator/docs/makefile-structure.md +530 -0
- package/skills/global_config/makefile-generator/docs/optimization-guide.md +784 -0
- package/skills/global_config/makefile-generator/docs/patterns-guide.md +642 -0
- package/skills/global_config/makefile-generator/docs/security-guide.md +361 -0
- package/skills/global_config/makefile-generator/docs/targets-guide.md +642 -0
- package/skills/global_config/makefile-generator/docs/variables-guide.md +596 -0
- package/skills/global_config/makefile-generator/scripts/add_standard_targets.sh +539 -0
- package/skills/global_config/makefile-generator/scripts/generate_makefile_template.sh +690 -0
- package/skills/global_config/makefile-generator/test/test_helper_scripts.sh +190 -0
- package/skills/global_config/makefile-validator/SKILL.md +244 -0
- package/skills/global_config/makefile-validator/docs/bake-tool.md +1000 -0
- package/skills/global_config/makefile-validator/docs/best-practices.md +858 -0
- package/skills/global_config/makefile-validator/docs/common-mistakes.md +944 -0
- package/skills/global_config/makefile-validator/examples/bad-makefile.mk +77 -0
- package/skills/global_config/makefile-validator/examples/good-makefile.mk +103 -0
- package/skills/global_config/makefile-validator/scripts/test_validate.sh +382 -0
- package/skills/global_config/makefile-validator/scripts/validate_makefile.sh +712 -0
- package/skills/global_config/{MCP_Manage → mcp-manage}/SKILL.md +3 -3
- package/skills/global_config/requesting-code-review/SKILL.md +98 -0
- package/skills/global_config/requesting-code-review/code-reviewer.md +198 -0
- package/skills/global_config/using-git-worktrees/SKILL.md +170 -0
- package/skills/global_config/verification-before-completion/SKILL.md +123 -0
- package/skills/global_config/writing-plans/SKILL.md +126 -46
- package/skills/global_config/writing-plans-legacy/SKILL.md +139 -0
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
# Regular Expressions Reference Guide
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Regular expressions (regex) are patterns used to match character combinations in strings. POSIX defines two flavors: Basic (BRE) and Extended (ERE).
|
|
6
|
+
|
|
7
|
+
**POSIX Specification:** https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html
|
|
8
|
+
|
|
9
|
+
## BRE vs ERE
|
|
10
|
+
|
|
11
|
+
| Feature | BRE | ERE |
|
|
12
|
+
|---------|-----|-----|
|
|
13
|
+
| One or more | `\+` | `+` |
|
|
14
|
+
| Zero or one | `\?` | `?` |
|
|
15
|
+
| Alternation | `\|` | `|` |
|
|
16
|
+
| Grouping | `\(...\)` | `(...)` |
|
|
17
|
+
| Quantifiers | `\{m,n\}` | `{m,n}` |
|
|
18
|
+
|
|
19
|
+
### Tool Usage
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# BRE (Basic)
|
|
23
|
+
grep 'pattern' file # BRE by default
|
|
24
|
+
sed 's/pattern/repl/' file # BRE by default
|
|
25
|
+
awk '/pattern/' file # ERE by default
|
|
26
|
+
|
|
27
|
+
# ERE (Extended)
|
|
28
|
+
grep -E 'pattern' file # ERE
|
|
29
|
+
egrep 'pattern' file # ERE (deprecated, use grep -E)
|
|
30
|
+
sed -E 's/pattern/repl/' file # ERE
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Basic Metacharacters (Both BRE and ERE)
|
|
34
|
+
|
|
35
|
+
### Single Character Matchers
|
|
36
|
+
```regex
|
|
37
|
+
. # Any single character except newline
|
|
38
|
+
[abc] # Any character in set (a, b, or c)
|
|
39
|
+
[^abc] # Any character NOT in set
|
|
40
|
+
[a-z] # Any character in range
|
|
41
|
+
[0-9] # Any digit
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Anchors
|
|
45
|
+
```regex
|
|
46
|
+
^ # Start of line
|
|
47
|
+
$ # End of line
|
|
48
|
+
\< # Start of word (GNU extension)
|
|
49
|
+
\> # End of word (GNU extension)
|
|
50
|
+
\b # Word boundary (some tools)
|
|
51
|
+
\B # Not a word boundary (some tools)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Quantifiers (Zero or More)
|
|
55
|
+
```regex
|
|
56
|
+
* # Zero or more of previous (both BRE and ERE)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Extended Metacharacters
|
|
60
|
+
|
|
61
|
+
### ERE Quantifiers
|
|
62
|
+
```regex
|
|
63
|
+
+ # One or more (ERE: +) (BRE: \+)
|
|
64
|
+
? # Zero or one (ERE: ?) (BRE: \?)
|
|
65
|
+
{n} # Exactly n (ERE: {n}) (BRE: \{n\})
|
|
66
|
+
{n,} # n or more (ERE: {n,}) (BRE: \{n,\})
|
|
67
|
+
{n,m} # Between n and m (ERE: {n,m}) (BRE: \{n,m\})
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Grouping and Alternation
|
|
71
|
+
```regex
|
|
72
|
+
# ERE
|
|
73
|
+
(pattern) # Group
|
|
74
|
+
pattern1|pattern2 # Alternation (OR)
|
|
75
|
+
|
|
76
|
+
# BRE (requires backslashes)
|
|
77
|
+
\(pattern\) # Group
|
|
78
|
+
pattern1\|pattern2 # Alternation (OR)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## POSIX Character Classes
|
|
82
|
+
|
|
83
|
+
Must be used inside bracket expressions `[[:class:]]`:
|
|
84
|
+
|
|
85
|
+
```regex
|
|
86
|
+
[:alnum:] # Alphanumeric [A-Za-z0-9]
|
|
87
|
+
[:alpha:] # Alphabetic [A-Za-z]
|
|
88
|
+
[:digit:] # Digits [0-9]
|
|
89
|
+
[:lower:] # Lowercase [a-z]
|
|
90
|
+
[:upper:] # Uppercase [A-Z]
|
|
91
|
+
[:space:] # Whitespace [ \t\n\r\f\v]
|
|
92
|
+
[:blank:] # Space and tab [ \t]
|
|
93
|
+
[:punct:] # Punctuation
|
|
94
|
+
[:xdigit:] # Hexadecimal [0-9A-Fa-f]
|
|
95
|
+
[:word:] # Word characters [A-Za-z0-9_] (GNU extension)
|
|
96
|
+
[:graph:] # Visible characters (not space)
|
|
97
|
+
[:print:] # Printable characters (including space)
|
|
98
|
+
[:cntrl:] # Control characters
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Usage
|
|
102
|
+
```bash
|
|
103
|
+
# Match any digit
|
|
104
|
+
grep '[[:digit:]]' file
|
|
105
|
+
|
|
106
|
+
# Match any whitespace
|
|
107
|
+
grep '[[:space:]]' file
|
|
108
|
+
|
|
109
|
+
# Match alphanumeric
|
|
110
|
+
grep '[[:alnum:]]' file
|
|
111
|
+
|
|
112
|
+
# Negation
|
|
113
|
+
grep '[^[:digit:]]' file # Not a digit
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Common Patterns
|
|
117
|
+
|
|
118
|
+
### Numbers
|
|
119
|
+
```bash
|
|
120
|
+
# BRE
|
|
121
|
+
[0-9] # Single digit
|
|
122
|
+
[0-9]\+ # One or more digits
|
|
123
|
+
[0-9]\{3\} # Exactly 3 digits
|
|
124
|
+
[0-9]\{3,5\} # 3 to 5 digits
|
|
125
|
+
|
|
126
|
+
# ERE
|
|
127
|
+
[0-9] # Single digit
|
|
128
|
+
[0-9]+ # One or more digits
|
|
129
|
+
[0-9]{3} # Exactly 3 digits
|
|
130
|
+
[0-9]{3,5} # 3 to 5 digits
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### IP Addresses
|
|
134
|
+
```bash
|
|
135
|
+
# Simple (BRE)
|
|
136
|
+
grep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' file
|
|
137
|
+
|
|
138
|
+
# Simple (ERE)
|
|
139
|
+
grep -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' file
|
|
140
|
+
|
|
141
|
+
# More strict (ERE)
|
|
142
|
+
grep -E '\b([0-9]{1,3}\.){3}[0-9]{1,3}\b' file
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Email Addresses
|
|
146
|
+
```bash
|
|
147
|
+
# Simple (ERE)
|
|
148
|
+
grep -E '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}' file
|
|
149
|
+
|
|
150
|
+
# BRE
|
|
151
|
+
grep '[a-zA-Z0-9._%+-]\+@[a-zA-Z0-9.-]\+\.[a-zA-Z]\{2,\}' file
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### URLs
|
|
155
|
+
```bash
|
|
156
|
+
# Simple HTTP/HTTPS (ERE)
|
|
157
|
+
grep -E 'https?://[a-zA-Z0-9./?=_-]+' file
|
|
158
|
+
|
|
159
|
+
# BRE
|
|
160
|
+
grep 'https\?://[a-zA-Z0-9./?=_-]\+' file
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Phone Numbers
|
|
164
|
+
```bash
|
|
165
|
+
# Format: 123-456-7890 (ERE)
|
|
166
|
+
grep -E '[0-9]{3}-[0-9]{3}-[0-9]{4}' file
|
|
167
|
+
|
|
168
|
+
# Format: (123) 456-7890 (ERE)
|
|
169
|
+
grep -E '\([0-9]{3}\) [0-9]{3}-[0-9]{4}' file
|
|
170
|
+
|
|
171
|
+
# BRE
|
|
172
|
+
grep '\([0-9]\{3\}\) [0-9]\{3\}-[0-9]\{4\}' file
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Dates
|
|
176
|
+
```bash
|
|
177
|
+
# YYYY-MM-DD (ERE)
|
|
178
|
+
grep -E '[0-9]{4}-[0-9]{2}-[0-9]{2}' file
|
|
179
|
+
|
|
180
|
+
# MM/DD/YYYY (ERE)
|
|
181
|
+
grep -E '[0-9]{2}/[0-9]{2}/[0-9]{4}' file
|
|
182
|
+
|
|
183
|
+
# BRE
|
|
184
|
+
grep '[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}' file
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Shell Script Patterns
|
|
188
|
+
|
|
189
|
+
### Variable Names
|
|
190
|
+
```bash
|
|
191
|
+
# Valid bash variable name (ERE)
|
|
192
|
+
grep -E '^[a-zA-Z_][a-zA-Z0-9_]*=' file
|
|
193
|
+
|
|
194
|
+
# Find variable usage
|
|
195
|
+
grep -E '\$[a-zA-Z_][a-zA-Z0-9_]*' file
|
|
196
|
+
grep -E '\$\{[a-zA-Z_][a-zA-Z0-9_]*\}' file
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Function Definitions
|
|
200
|
+
```bash
|
|
201
|
+
# POSIX function (ERE)
|
|
202
|
+
grep -E '^[a-zA-Z_][a-zA-Z0-9_]*\s*\(\)' file
|
|
203
|
+
|
|
204
|
+
# Bash function keyword (ERE)
|
|
205
|
+
grep -E '^function [a-zA-Z_][a-zA-Z0-9_]*' file
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Comments
|
|
209
|
+
```bash
|
|
210
|
+
# Shell comments
|
|
211
|
+
grep '^[[:space:]]*#' file
|
|
212
|
+
|
|
213
|
+
# Uncommented lines
|
|
214
|
+
grep -v '^[[:space:]]*#' file
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Escaping Special Characters
|
|
218
|
+
|
|
219
|
+
Characters that need escaping (context-dependent):
|
|
220
|
+
|
|
221
|
+
```regex
|
|
222
|
+
. * [ ] ^ $ \ ( ) { } + ? |
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Literal Matching
|
|
226
|
+
```bash
|
|
227
|
+
# Match literal dot (BRE and ERE)
|
|
228
|
+
grep '\.' file
|
|
229
|
+
|
|
230
|
+
# Match literal asterisk
|
|
231
|
+
grep '\*' file
|
|
232
|
+
|
|
233
|
+
# Match literal dollar sign
|
|
234
|
+
grep '\$' file
|
|
235
|
+
|
|
236
|
+
# Match literal brackets
|
|
237
|
+
grep '\[' file
|
|
238
|
+
grep '\]' file
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Backreferences
|
|
242
|
+
|
|
243
|
+
### Capture and Reuse
|
|
244
|
+
```bash
|
|
245
|
+
# BRE - capture with \(...\), reference with \1, \2, etc.
|
|
246
|
+
sed 's/\([0-9]\+\)-\([0-9]\+\)/\2-\1/' file # Swap numbers
|
|
247
|
+
|
|
248
|
+
# ERE - capture with (...), reference with \1, \2, etc.
|
|
249
|
+
sed -E 's/([0-9]+)-([0-9]+)/\2-\1/' file
|
|
250
|
+
|
|
251
|
+
# Find duplicate words
|
|
252
|
+
grep -E '\b([a-z]+) \1\b' file
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Examples
|
|
256
|
+
```bash
|
|
257
|
+
# Extract and rearrange (BRE)
|
|
258
|
+
sed 's/\([A-Z][a-z]*\), \([A-Z][a-z]*\)/\2 \1/' file
|
|
259
|
+
|
|
260
|
+
# ERE
|
|
261
|
+
sed -E 's/([A-Z][a-z]*), ([A-Z][a-z]*)/\2 \1/' file
|
|
262
|
+
|
|
263
|
+
# Find repeated lines
|
|
264
|
+
grep -E '^(.*)$\n\1$' file
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
## Greedy vs Non-Greedy
|
|
268
|
+
|
|
269
|
+
POSIX regex is always greedy (matches longest possible string):
|
|
270
|
+
|
|
271
|
+
```bash
|
|
272
|
+
# Always greedy in POSIX
|
|
273
|
+
echo "foo bar baz" | grep -o 'f.*b' # Matches "foo bar b"
|
|
274
|
+
|
|
275
|
+
# For non-greedy, you need to be creative
|
|
276
|
+
echo "foo bar baz" | grep -o 'f[^b]*b' # Matches "foo b"
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
## Lookahead and Lookbehind
|
|
280
|
+
|
|
281
|
+
**NOT supported in POSIX BRE/ERE**. Only available in PCRE (Perl-Compatible Regular Expressions):
|
|
282
|
+
|
|
283
|
+
```bash
|
|
284
|
+
# PCRE only (not POSIX)
|
|
285
|
+
grep -P '(?<=foo)bar' file # Lookbehind
|
|
286
|
+
grep -P 'foo(?=bar)' file # Lookahead
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
## Common Mistakes
|
|
290
|
+
|
|
291
|
+
### 1. Forgetting to Escape in BRE
|
|
292
|
+
```bash
|
|
293
|
+
# Wrong (BRE)
|
|
294
|
+
grep '(foo|bar)' file
|
|
295
|
+
|
|
296
|
+
# Right (BRE)
|
|
297
|
+
grep '\(foo\|bar\)' file
|
|
298
|
+
|
|
299
|
+
# Or use ERE
|
|
300
|
+
grep -E '(foo|bar)' file
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
### 2. Using + in BRE Without Escape
|
|
304
|
+
```bash
|
|
305
|
+
# Wrong (BRE)
|
|
306
|
+
grep '[0-9]+' file
|
|
307
|
+
|
|
308
|
+
# Right (BRE)
|
|
309
|
+
grep '[0-9]\+' file
|
|
310
|
+
|
|
311
|
+
# Or use ERE
|
|
312
|
+
grep -E '[0-9]+' file
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### 3. Not Escaping Dots for Literal Match
|
|
316
|
+
```bash
|
|
317
|
+
# Wrong - matches any character
|
|
318
|
+
grep '192.168.1.1' file
|
|
319
|
+
|
|
320
|
+
# Right - matches literal dots
|
|
321
|
+
grep '192\.168\.1\.1' file
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### 4. Greedy Matching Issues
|
|
325
|
+
```bash
|
|
326
|
+
# Matches too much
|
|
327
|
+
echo '<tag>content</tag>' | sed 's/<.*>//' # Empty!
|
|
328
|
+
|
|
329
|
+
# Better
|
|
330
|
+
echo '<tag>content</tag>' | sed 's/<[^>]*>//'
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### 5. Character Class Mistakes
|
|
334
|
+
```bash
|
|
335
|
+
# Wrong - not a range
|
|
336
|
+
grep '[a-Z]' file # Undefined behavior
|
|
337
|
+
|
|
338
|
+
# Right
|
|
339
|
+
grep '[a-zA-Z]' file
|
|
340
|
+
|
|
341
|
+
# Or use POSIX class
|
|
342
|
+
grep '[[:alpha:]]' file
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
## Testing Regex
|
|
346
|
+
|
|
347
|
+
### Online Tools
|
|
348
|
+
- regex101.com (supports PCRE, not POSIX)
|
|
349
|
+
- regexr.com
|
|
350
|
+
- regexpal.com
|
|
351
|
+
|
|
352
|
+
### Command Line Testing
|
|
353
|
+
```bash
|
|
354
|
+
# Test with echo
|
|
355
|
+
echo "test string" | grep 'pattern'
|
|
356
|
+
|
|
357
|
+
# Show matches only
|
|
358
|
+
echo "test string" | grep -o 'pattern'
|
|
359
|
+
|
|
360
|
+
# Test with multiple lines
|
|
361
|
+
printf 'line1\nline2\nline3\n' | grep 'pattern'
|
|
362
|
+
|
|
363
|
+
# Color highlighting
|
|
364
|
+
grep --color=always 'pattern' file | less -R
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
## Quick Reference Table
|
|
368
|
+
|
|
369
|
+
| Pattern | BRE | ERE | Matches |
|
|
370
|
+
|---------|-----|-----|---------|
|
|
371
|
+
| Literal | `abc` | `abc` | abc |
|
|
372
|
+
| Any char | `.` | `.` | any single character |
|
|
373
|
+
| Start | `^` | `^` | start of line |
|
|
374
|
+
| End | `$` | `$` | end of line |
|
|
375
|
+
| Zero or more | `*` | `*` | 0+ of previous |
|
|
376
|
+
| One or more | `\+` | `+` | 1+ of previous |
|
|
377
|
+
| Zero or one | `\?` | `?` | 0 or 1 of previous |
|
|
378
|
+
| Exactly n | `\{n\}` | `{n}` | exactly n |
|
|
379
|
+
| n or more | `\{n,\}` | `{n,}` | n or more |
|
|
380
|
+
| n to m | `\{n,m\}` | `{n,m}` | between n and m |
|
|
381
|
+
| Group | `\(...\)` | `(...)` | capture group |
|
|
382
|
+
| Alternation | `\|` | `|` | OR |
|
|
383
|
+
| Character class | `[abc]` | `[abc]` | a, b, or c |
|
|
384
|
+
| Negated class | `[^abc]` | `[^abc]` | not a, b, or c |
|
|
385
|
+
| Range | `[a-z]` | `[a-z]` | lowercase letters |
|
|
386
|
+
|
|
387
|
+
## Resources
|
|
388
|
+
|
|
389
|
+
- [POSIX Regular Expressions](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html)
|
|
390
|
+
- [Regular-Expressions.info](https://www.regular-expressions.info/posix.html)
|
|
391
|
+
- [GNU grep Manual - Regular Expressions](https://www.gnu.org/software/grep/manual/html_node/Regular-Expressions.html)
|