Skip to content

New feature: Patterns#184

Merged
4 commits merged intokaifcodec:mainfrom
VamatoHD:pattern
Mar 5, 2026
Merged

New feature: Patterns#184
4 commits merged intokaifcodec:mainfrom
VamatoHD:pattern

Conversation

@VamatoHD
Copy link
Copy Markdown
Collaborator

@VamatoHD VamatoHD commented Feb 3, 2026

This is a draft of a new feature that replaces generate_permutations entirely.
It's a small parser I wrote that converts and expands the string based on [<chars>]{<lens>}.

Syntax:

When you want an automatic pattern to be expanded, you use:
[<list of characters>] followed by (optional) {<list of lengths separated by ";">}

For example:

  • "john[a-z]" -> "johna", "johnb", "johnc"...
  • john_doe[0-9]{0-2} -> "john_doe", "john_doe0", "john_doe1" ... ""john_doe99"

TODO:

  • Randomizing generation
  • Testing
  • Improve overall code
  • Documentation

@json-hunter07
Copy link
Copy Markdown
Collaborator

@VamatoHD Nice idea, to be honest. The permutation feature was a bit inconsistent, it produced random username and email variations without much control. This approach gives users a lot more control and flexibility.

@VamatoHD VamatoHD marked this pull request as ready for review February 4, 2026 07:16
@VamatoHD VamatoHD marked this pull request as draft February 4, 2026 07:25
@kaifcodec
Copy link
Copy Markdown
Owner

@VamatoHD I resolved the conflicts in __main__.py. The conflicts occurred because PRs #183 and #184 were opened around the same time, and both modified __main__.py. I’ve fixed and resolved the conflict so take a look and check __main__.py again if it aligns with your pattern implementation.

@VamatoHD
Copy link
Copy Markdown
Collaborator Author

I've added a function to iterate the usernames/emails randomly.
Sadly, I haven't got much time to improve the code and add documentation.

@VamatoHD VamatoHD added help wanted Extra attention is needed need-extra-changes Some files or parts of the code may require additional edits or updates for it work properly. labels Feb 13, 2026
@thumpersecure
Copy link
Copy Markdown
Contributor

#184

This is a draft of a new feature that replaces generate_permutations entirely. It's a small parser I wrote that converts and expands the string based on [<chars>]{<lens>}.

Syntax:

When you want an automatic pattern to be expanded, you use: [<list of characters>] followed by (optional) {<list of lengths separated by ";">}

For example:

  • "john[a-z]" -> "johna", "johnb", "johnc"...
  • john_doe[0-9]{0-2} -> "john_doe", "john_doe0", "john_doe1" ... ""john_doe99"

TODO:

  • Randomizing generation
  • Testing
  • Improve overall code
  • Documentation

SylvainM98 added a commit to SylvainM98/user-scanner that referenced this pull request Mar 2, 2026
Cover expand_patterns and expand_patterns_random:
- Plain text, charset ranges, explicit chars, prefix/suffix
- Lenset: single values, ranges, semicolons, zero-length
- Escaped characters: brackets, backslash, inside charset
- Error cases: unclosed brackets/braces, unmatched close bracket
- Complex: multiple blocks, mixed text and patterns
- Random: set equivalence, reservoir sampling, islice

Ref kaifcodec#184
SylvainM98 added a commit to SylvainM98/user-scanner that referenced this pull request Mar 2, 2026
- Fix `if res:` to `if res is not None:` in parse_number (falsy when 0)
- Add descriptive message to bare ValueError in charset range
- Replace `[char for char in input]` with `list(input)`
- Rename `list` parameter to `blocks` to avoid shadowing builtin
- Fix typo "unscaped" to "unescaped"
- Remove redundant sorted() call (lenset already sorted at construction)

Ref kaifcodec#184
SylvainM98 added a commit to SylvainM98/user-scanner that referenced this pull request Mar 2, 2026
Add count_patterns(input) -> int that returns the total number of
expansions without generating them. Runs in O(number of blocks),
useful for informing users how many permutations a pattern produces.

Add docstrings to all public functions: expand_patterns,
expand_patterns_random, and count_patterns.

Ref kaifcodec#184
SylvainM98 added a commit to SylvainM98/user-scanner that referenced this pull request Mar 3, 2026
Use count_patterns() to display how many permutations exist in total,
e.g. "Scanning 5 of 111 permutations" instead of "Generated 5 permutations".
Gives users visibility into the full scope of their pattern.

Ref kaifcodec#184
@SylvainM98
Copy link
Copy Markdown
Contributor

Hey @VamatoHD, I opened #265 to help with the remaining TODO items:

  • Testing: 51 unit tests covering expand_patterns, expand_patterns_random, and a new count_patterns function
  • Code quality: 6 fixes (if res: bug, typo, shadowed builtin, etc.)
  • Documentation: Docstrings on all public functions
  • CLI: Updated the permutation message to show total count (e.g. "Scanning 5 of 111 permutations")

The PR is based on your pattern branch. Let me know if you'd like any changes!

@kaifcodec kaifcodec closed this pull request by merging all changes into kaifcodec:main in a7420e4 Mar 5, 2026
@VamatoHD VamatoHD deleted the pattern branch March 5, 2026 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wanted Extra attention is needed need-extra-changes Some files or parts of the code may require additional edits or updates for it work properly.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants