Identifiers
Most languages: letter or underscore, then letters/digits/underscores.
[a-zA-Z_]\w*
For naming conventions:
- camelCase:
[a-z][a-zA-Z0-9]* - snake_case:
[a-z][a-z0-9_]* - SCREAMING_SNAKE:
[A-Z][A-Z0-9_]* - PascalCase:
[A-Z][a-zA-Z0-9]* - kebab-case:
[a-z][a-z0-9-]*
Comments
Single-line C-style: //[^\n]* or anchored ^//.*$ with MULTILINE.
Single-line shell/Python: #[^\n]* (watch for false positives — # in URLs, in strings).
Multi-line C-style: /\*[\s\S]*?\*/ — note [\s\S] instead of . to span newlines without DOTALL flag.
Real comment detection requires a tokenizer — comment-like patterns inside strings will false-positive. For source-code processing, use a real parser/AST when accuracy matters.
Code mods
Regex shines for refactoring across files: rename a function, change an import, restructure a config block. Use VS Code's regex find/replace or sed for one-shot mods. For complex refactors, AST tools (Python libcst, JS jscodeshift) are safer.