-
Notifications
You must be signed in to change notification settings - Fork 0
FAQ
- Installation & Setup
- Basic Usage
- Advanced Features
- Troubleshooting
- Performance & Optimization
- Integration & Automation
- Best Practices
- Support & Contribution
A: sr-search-replace is designed to work on:
- Operating Systems: Windows, Linux, macOS
- PHP Version: 7.4 or higher (8.0+ recommended)
- Dependencies: Standard PHP extensions (PCRE for regex support)
- Disk Space: Minimal (< 5 MB for installation)
A: Installation steps:
# Clone the repository
git clone https://github.com/paulmann/sr-search-replace.git
cd sr-search-replace
# Install dependencies (if using Composer)
composer install
# Make executable (Linux/macOS)
chmod +x sr-search-replaceA: Yes. After cloning, symlink the binary to your system PATH:
sudo ln -s /path/to/sr-search-replace/sr-search-replace /usr/local/bin/sr-search-replaceA: The tool requires:
-
pcre(for regex pattern matching) -
spl(Standard PHP Library) -
reflection(for code analysis features) Most standard PHP installations include these by default.
A: sr-search-replace is a powerful search and replace utility that allows you to:
- Search for text patterns using regular expressions or literal strings
- Replace matches with new content
- Process single files or entire directory trees
- Preview changes before applying them
- Maintain backup copies of modified files
A: Basic usage:
sr-search-replace --find="pattern" --replace="replacement" --file="path/to/file"A: Yes. Enable regex mode with the --regex or -r flag:
sr-search-replace -r --find="pattern\d+" --replace="NUM-$1" --file="test.txt"A: Use the recursive flag:
sr-search-replace --find="old" --replace="new" --directory="/path" --recursiveA:
- Case-sensitive (default): Matches exact character case
-
Case-insensitive: Use
-iflag to ignore case:
sr-search-replace -i --find="Hello" --replace="Hi" --file="test.txt"A: Use the --dry-run or -d flag:
sr-search-replace --dry-run --find="old" --replace="new" --file="file.txt"This shows what would be changed without modifying the file.
A: Yes. Enable backup with the --backup flag:
sr-search-replace --backup --find="old" --replace="new" --file="file.txt"Backups are created with .bak extension.
A: Use parentheses for groups and $1, $2, etc. for replacement:
sr-search-replace -r --find="(\w+)@(\w+\.\w+)" --replace="$1 [$2]" --file="emails.txt"A: Yes. Create a configuration file:
# replacements.yml
replacements:
- find: "old1"
replace: "new1"
- find: "old2"
replace: "new2"Then run:
sr-search-replace --config="replacements.yml" --file="target.txt"A: Use \b for word boundaries:
sr-search-replace -r --find="\bword\b" --replace="replacement" --file="file.txt"A: Escape them with backslash or use raw strings:
sr-search-replace --find="\$amount" --replace="\$price" --file="config.php"A: Common causes:
- Check the file path is correct
- Verify file permissions (must be readable)
- Use absolute paths when possible:
sr-search-replace --find="old" --replace="new" --file="/absolute/path/file.txt"A: Troubleshooting steps:
- Enable dry-run to check without making changes
- Test your regex pattern separately
- Ensure you're using double backslashes:
\dnot single slash - Check for hidden characters in your search pattern
- Verify case sensitivity settings
A: The tool handles UTF-8 by default. For other encodings:
sr-search-replace --encoding="ISO-8859-1" --find="pattern" --replace="new" --file="file.txt"A: Yes, if backup was enabled:
sr-search-replace --restore --file="file.txt"Otherwise, use version control or your backup strategy.
A: The tool doesn't have write access. Solutions:
- Check file ownership:
ls -l filename - Change permissions:
chmod 644 filename - Run with elevated privileges if necessary (use caution)
A: Optimization strategies:
- Use specific patterns instead of broad matches
- Process smaller chunks with
--line-by-line - Disable backup if not needed:
--no-backup - Use character classes instead of alternation:
[abc]not(a|b|c)
A: The tool implements efficient streaming for large files:
- Memory usage is optimized through buffering
- Line-by-line processing available with
--line-by-line - Typical performance: 10MB+ files in seconds
A: Best practices:
- Use specific patterns:
[0-9]{3}is faster than.*\d.* - Avoid unnecessary quantifiers:
a*vsa+ - Use atomic groups for complex patterns:
(?>group) - Test performance with dry-run first
A: Yes, the --parallel flag enables multi-threading:
sr-search-replace --parallel --find="pattern" --replace="new" --directory="/path" --recursiveA: Example for GitHub Actions:
- name: Search and Replace
run: |
sr-search-replace --find="VERSION=.*" --replace="VERSION=1.2.3" --file="config.txt"A: Yes, require the library:
require 'vendor/autoload.php';
use Paulmann\SearchReplace\Engine;
$engine = new Engine();
$result = $engine->replace('old', 'new', '/path/to/file');A: Via Composer:
composer require paulmann/sr-search-replaceA: Yes, use extension filters:
sr-search-replace --find="pattern" --replace="new" --directory="/path" --extensions="php,js,css" --recursiveA: Recommended workflow:
-
Always use
--dry-runfirst - Ensure backups are enabled
- Test on a small sample first
- Review the preview output carefully
- Use version control (git, etc.)
- Keep a separate backup of original files
- Document all changes in commit messages
A: No. Use literal mode for simple cases:
# Good - clear intent
sr-search-replace --find="hello" --replace="hi" --file="test.txt"
# Avoid unnecessary complexity
sr-search-replace -r --find="hello" --replace="hi" --file="test.txt"A: Best practice:
# Always use dry-run first
sr-search-replace --dry-run --find="old" --replace="new" --directory="." --recursive
# Then apply with git awareness
git add -A
sr-search-replace --find="old" --replace="new" --directory="." --recursive --backup
git diff --statA: Create a test environment:
# Copy files to test directory
cp -r original/ test/
# Run replacement on test copies
sr-search-replace --find="pattern" --replace="new" --directory="test" --recursive
# Verify results
diff -r original/ test/A: Use the GitHub Issues tracker:
- sr-search-replace Issues
- Include: error message, command used, minimal reproduction case
- Attach sample files if possible (sanitized for confidentiality)
A: Contributions are welcome!
- Fork the repository
- Create a feature branch
- Write tests for new features
- Submit a pull request with description
- See Contributing Guidelines
A: For commercial support inquiries:
- Email: sr@devnekin.com
- Subject: "Commercial Support - sr-search-replace"
- Responses typically within 24-48 hours
A: sr-search-replace is licensed under the MIT License. See LICENSE file for details. You're free to:
- Use commercially
- Modify the source
- Distribute As long as you include the original license and copyright notice.
A: Development cycle:
- Critical bug fixes: immediate
- Feature releases: every 2-4 weeks
- Major versions: as needed (typically quarterly)
- Security updates: highest priority
- Main Documentation: Home Wiki
- Command Reference: CLI Reference
- Configuration Guide: Configuration
- Examples: Usage Examples
- GitHub Repository: paulmann/sr-search-replace
Last Updated: 2025 Maintained by: Paul Mann Community: GitHub Issues and Discussions