From 1ac918f969c701b4d133ef78a7c2a14840c28b3d Mon Sep 17 00:00:00 2001 From: "Federico G. Schwindt" Date: Wed, 26 Jun 2019 21:22:23 +0100 Subject: [PATCH] Add support for \w --- exrex.py | 6 +++++- tests.py | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/exrex.py b/exrex.py index b8f4aa2..f98fd7a 100644 --- a/exrex.py +++ b/exrex.py @@ -23,7 +23,7 @@ except: pass from re import sre_parse, U -from itertools import tee +from itertools import tee, chain from random import choice, randint from types import GeneratorType @@ -47,6 +47,10 @@ CATEGORIES = { sre_parse.CATEGORY_SPACE: sorted(sre_parse.WHITESPACE), sre_parse.CATEGORY_DIGIT: sorted(sre_parse.DIGITS), + sre_parse.CATEGORY_WORD: [unichr(x) for x in chain(range(48, 58), + range(65, 91), + range(95, 96), + range(97, 123))], 'category_any': [unichr(x) for x in range(32, 123)] } diff --git a/tests.py b/tests.py index 2e05b55..ea61ac6 100644 --- a/tests.py +++ b/tests.py @@ -44,7 +44,8 @@ '[áíő]': [u'á', u'í', u'ő'], '(a|b)(1|2)\\1\\2\\1\\2': ['a1a1a1', 'a2a2a2', 'b1b1b1', 'b2b2b2'], '(?=x)': ['x'], - '\\da{2}': ['0aa', '1aa', '2aa', '3aa', '4aa', '5aa', '6aa', '7aa', '8aa', '9aa'] + '\\da{2}': ['0aa', '1aa', '2aa', '3aa', '4aa', '5aa', '6aa', '7aa', '8aa', '9aa'], + '\w': ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '_', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] } BIGS = [