Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't define different classes for each character #3

Merged
merged 1 commit into from
Dec 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 9 additions & 46 deletions regexfactory/chars.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,11 @@
r"""Module for regex characters like `\w` or `\D` or `.`"""
r"""Module for common regex characters, such as `\d`, `.`, ..."""

from .pattern import RegexPattern, escape
from .patterns import RegexPattern


class RegexChar(RegexPattern):
regex: str = ''

def __init__(self, character: str = None):
if character:
self.regex = escape(character)


class Whitespace(RegexChar):
regex = r'\s'


class NotWhitespace(RegexChar):
regex = r'\S'


class Any(RegexChar):
regex = r'.'


class Word(RegexChar):
regex = r'\w'


class NotWord(RegexChar):
regex = r'\W'


class Digit(RegexChar):
regex = r'\d'


class NotDigit(RegexChar):
regex = r'\D'


ANY = Any()
WHITESPACE = Whitespace()
NOTWHITESPACE = NotWhitespace()
WORD = Word()
NOTWORD = NotWord()
DIGIT = Digit()
NOTDIGIT = NotDigit()
ANY = RegexPattern(r".")
WHITESPACE = RegexPattern(r"\s")
NOTWHITESPACE = RegexPattern(r"\S")
WORD = RegexPattern(r"\w")
NOTWORD = RegexPattern(r"\W")
DIGIT = RegexPattern(r"\d")
NOTDIGIT = RegexPattern(r"\D")