Skip to content

Add pattern helper for direct character class notation #548

@cdwmhcc

Description

@cdwmhcc

🆒 Your use case

When working with simple character classes, I often find myself wanting to directly use traditional regex notation.

For example, I need to match any of whitespace, dash, or underscore characters.
With standard RegExp I can simply write /[-_\s]/, but with magic-regexp I need to use a combination of anyOf(whitespace, charIn('-_')) which produces a more complex pattern with capture groups and alternation.

🔍 Alternatives you've considered

anyOf(whitespace, charIn('-_'))

ℹ️ Additional info

A pattern helper could allow direct use of regex notation when needed:

pattern('[-_\\s]').toString() // => "[-_\\s]"

refer to: https://github.com/slevithan/regex

This would maintain the type-safety and readability benefits of magic-regexp while allowing for more concise expressions in specific cases.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions