https://github.com/sleepytariq/regex-filter
Replace matched strings in file names or file content with specified substitute using regular expressions
https://github.com/sleepytariq/regex-filter
python3 regular-expression
Last synced: 9 months ago
JSON representation
Replace matched strings in file names or file content with specified substitute using regular expressions
- Host: GitHub
- URL: https://github.com/sleepytariq/regex-filter
- Owner: sleepytariq
- License: unlicense
- Created: 2022-08-13T09:28:29.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-07-22T10:42:27.000Z (almost 3 years ago)
- Last Synced: 2024-05-03T04:53:15.026Z (about 2 years ago)
- Topics: python3, regular-expression
- Language: Python
- Homepage:
- Size: 94.7 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Installation
1. Clone the repository `git clone https://github.com/illbison/regex-filter` or download as [zip](https://github.com/illbison/regex-filter/archive/refs/heads/main.zip)
2. Install dependencies `pip install -r requirements.txt`
3. (Optional) Install 7zip and add it to your PATH variable to handle compressed files
4. Run with `python regex_filter.py ...`
## Usage
```console
usage: regex_filter.py -i INPUT [INPUT ...] -f FILTER -o OUTPUT [-m] [-r] [-l] [-h]
Replace matched strings in file content and file names with specified substitute using regular expressions
Required:
-i INPUT [INPUT ...], --input INPUT [INPUT ...]
Path to files or directories containing files
-f FILTER, --filter FILTER
Path to a json file in REGEX:WORD format
-o OUTPUT, --output OUTPUT
Path to output directory
Modifiers:
-m, --modify Use filter to modify content of files
-r, --rename Use filter to rename files
Optional:
-l, --log Log changes to a text file, NOTE: should only be used to debug the regex
-h, --help Show this help message and exit
```
The json file must be in `REGEX:WORD` format where the keys are the regex and the values are the replacement. See [example](example.json)
A new directory named `REGEX_FILTER` will be created in the given output directory containing the cleaned input