E5D3 GitHub - SpectralZero/Regex
[go: up one dir, main page]

Skip to content

SpectralZero/Regex

Repository files navigation

Regex — Advanced Regex Tool

One-liner: A powerful, GUI-driven regex utility for red teams, pentesters, and developers — build, test, catalog and apply regular expressions with presets, live testing, and an extensible pattern library.


Table of Contents


About

This repository provides an Advanced Regex Tool implemented in Python with a GUI layer. It aims to be a professional tool for interactive regex construction, validation, and application to real-world red‑team and developer tasks (logs, data extraction, reconnaissance, input validation, payload shaping).

The README below assumes the project is the single-file GUI application advanced_regex_tool.py backed by a centralized pattern_library.py and a presets JSON file. The layout is designed for maintainers and contributors who want a high-quality README suitable for published open-source projects and pentest toolkits.


Features

  • Interactive GUI for building and testing regular expressions.
  • Pattern library with categorized reusable patterns and presets (emails, IPs, URLs, tokens, hashes, credentials, etc.).
  • JSON-based presets for quick matching and sample payloads.
  • Save/load presets and export pattern sets.
  • Real-time match highlighting, explained capture groups, an FF8 d replacement preview.
  • Utilities to generate synthetic test data from regex presets (for fuzzing and testing parsers).
  • Audit/logging capabilities (regex_tool_audit.log) for reproducible test runs.
  • Theme customization and user-friendly UI (Theme.py).
  • Designed for offline usage (no telemetry) — suitable for restricted/air-gapped pentest environments.

Repository structure (file map)

Short map of files and what they do (use this as a quick guide for contributors):

  • advanced_regex_tool.pyMain application (entrypoint). Implements GUI, event handlers, pattern tester, and export features.
  • pattern_library.pyPattern library module. Contains categorized regex patterns, helper functions to fetch/search patterns, and documentation strings for each pattern.
  • regex_presets.jsonPresets & sample payloads. JSON file listing preset patterns and sample inputs for quick testing and templates.
  • Theme.pyUI theming. Centralized color, font, and layout configuration used by the GUI (light/dark/retro modes, etc.).
  • requirements.txtPython dependencies required to run the GUI and supporting modules.
  • assets/ — Static assets used by the UI (icons, images, screenshots).

Tip: Keep the pattern_library.py focused on pure data — minimal side effects — so it can be safely imported in CI and unit tests.


Requirements & Installation

System requirements

  • Python 3.10+ recommended (backwards compatibility depends on used libraries).
  • Works on Windows, Linux, and macOS (GUI toolkit dependent — see requirements.txt).

Install (recommended, in virtualenv)

python -m venv .venv
source .venv/bin/activate  # or `.venv\Scripts\activate` on Windows
pip install --upgrade pip
pip install -r requirements.txt

Run the app

python advanced_regex_tool.py

If you prefer to run from source with editable installs for development:

pip install -e .

(If a setup.py / pyproject.toml is added later, prefer using pip install -e ..)


Quick Start

  1. Launch the application: python advanced_regex_tool.py.
  2. Load a preset from regex_presets.json via File → Load Preset.
  3. Type or paste test input into the Input panel.
  4. Build or paste a regex in the Pattern field and press Test / Run.
  5. Inspect matches, capture groups, and replacement preview in the Results panel.
  6. Save successful patterns to the pattern library or export them as JSON.

GUI Walkthrough & Usage

Main panels

  • Pattern Editor — Where you type or assemble regex pieces. Supports named placeholders and helpers.
  • Preset Browser — Category view of common patterns (IP, email, URL, credit card, hash, JWT, etc.).
  • Input / Test Case — Paste raw data you want to match against. Multi-line support included.
  • Results / Explanation — Match list, named groups, start/end indexes, and a short natural language explanation for each capture (where possible).
  • Generator utilities — Produce fake inputs from presets for testing downstream parsers and fuzzers.(Disabled)

Power user features

  • Toggle multiline / DOTALL / IGNORECASE / VERBOSE flags.
  • Visual group numbering and replacement preview.
  • Export selected patterns to regex_presets.json or to clipboard.
  • Audit logging toggle — keep a private activity log for test repeatability.

Pattern Library & Presets

Organization

  • Patterns are grouped (e.g., network, identity, tokens, filepaths, hashes).
  • Each pattern entry should include: name, description, pattern, flags, and examples.

Example pattern entry (JSON)

{
  "name": "IPv4 (strict)",
  "description": "Matches valid IPv4 addresses 0.0.0.0 - 255.255.255.255",
  "pattern": "(?:(?:25[0-5]|2[0-4]\d|[01]?\d?\d)(?:\.|$)){4}",
  "flags": "",
  "examples": ["192.168.1.1", "8.8.8.8"]
}

Maintainer best practices

  • Keep patterns readable: use inline comments and re.VERBOSE when patterns are complex.
  • Add strict and permissive variants where appropriate (for discovery vs. validation).
  • Provide at least 2–3 positive and negative examples per pattern for tests.

Advanced Workflows & Integrations

For Red Teamers & Pentesters

  • Use the pattern generator to produce test payloads for log ingestion or WAF bypass testing.
  • Chain regex extraction with output → CSV export → pivot into other reconnaissance tools.
  • Integrate with Auto-Exploit Tool style modules by exporting a curated set of patterns for scanning (bulk match across large targets).

For Developers

  • Validate user inputs (emails, IPs, tokens) by using a strict validation variant from the library.
  • Use presets to seed unit tests and fuzzers.

Automation

  • CLI mode (not present yet) should support --run-presets, --export-results, --audit-log, and --headless options to integrate into CI pipelines.

Extending & Development Guide

Code style & tests

  • Use black and ruff/flake8 for consistent formatting and linting.
  • Add unit tests under tests/ that cover pattern matching, serialization, and GUI-critical flows (if GUI logic is separated from presentation).

Module responsibilities

  • pattern_library.py — data only (no UI I/O), with simple APIs: get_pattern(name), search(query), list_categories().
  • advanced_regex_tool.py — should import the library, wire UI, and keep business logic minimal in the UI layer.
  • Theme.py — purely theme constants and helper accessors.

Suggested development tasks

  • Split GUI code into ui/ package if the file grows beyond ~1500–2000 lines.
  • Add a dedicated CLI entry-point (console_scripts) for headless usage.
  • Add example pyproject.toml and pre-commit hooks.

Security Considerations

  • Never run untrusted regexes against data with catastrophic backtracking without timeouts/limits — provide a sandboxed execution or a regex timeout.
  • Sanitize exported logs containing sensitive matched data; provide opt-in redaction or per-pattern redaction rules.
  • If the app offers pastebin or sharing features, warn users about PII and default to local-only exports.

Regex ReDoS mitigation

  • Use safe matching libraries (e.g., regex package with timeouts) or run regex evaluation in a subprocess with controlled CPU/time limits.
  • Provide an option to analyze a pattern's worst-case complexity and suggest safer alternatives.

Testing & QA

  • Unit tests: patterns, serialization, example IO.
  • Fuzz tests: generate inputs from presets and run them through each pattern to ensure no catastrophic behavior.
  • GUI tests: keep the UI logic thin and test it using a combination of unit tests for logic and manual QA for UX.

Contribution Guidelines

  1. Fork the repository.
  2. Create a feature branch: git checkout -b feat/my-new-pattern.
  3. Add tests for any new pattern or behavior (in tests/).
  4. Run linters and formatters, then open a PR describing the change.

Code of conduct

  • Be respectful. Follow normal open-source etiquette.

Changelog & Roadmap (Suggested)

  • v0.x — Core GUI + pattern library + presets.
  • v0.x+1 — CLI/headless mode, safe-runtime for regexes.
  • v1.0 — Stable API, packaged releases, built installers for Windows/macOS.

Quick Copy-paste Examples

Test an IP

# pattern (permissive)
\b(?:\d{1,3}\.){3}\d{1,3}\b

# strict — removes values >255 using a more precise subpattern
(?:(?:25[0-5]|2[0-4]\d|[01]?\d?\d)(?:\.|$)){4}

Export sample JSON entry to add to regex_presets.json

{
  "category": "network",
  "name": "IPv4 - strict",
  "pattern": "(?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)(?:\\.|$)){4}",
  "description": "Strict IPv4 pattern",
  "examples": ["192.168.0.1"]
}

Credits & License

  • Author: SpectralZero
  • License: MIT LICENSE.

Last Updated: Version 2.0 | 2024

GitHub

---

alt text

alt text

alt text

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0