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

No number fix #33

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion cleantext/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
)

NUMBERS_REGEX = re.compile(
r"(?:^|(?<=[^\w,.]))[+–-]?(([1-9]\d{0,2}(,\d{3})+(\.\d*)?)|([1-9]\d{0,2}([ .]\d{3})+(,\d*)?)|(\d*?[.,]\d+)|\d+)(?:$|(?=\b))"
r"((?<=[a-zA-Z])\d+)|(\d+(?=[a-zA-Z]))|(?:^|(?<=[^\w,.]))[+–-]?(([1-9]\d{0,2}(,\d{3})+(\.\d*)?)|([1-9]\d{0,2}([ .]\d{3})+(,\d*)?)|(\d*?[.,]\d+)|\d+)(?:$|(?=\b))"
)

LINEBREAK_REGEX = re.compile(r"((\r\n)|[\n\v])+")
Expand Down
4 changes: 2 additions & 2 deletions tests/test_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def test_replace_phone_numbers():


def test_replace_numbers():
text = "I owe $1,000.99 to 123 people for 2 +1 reasons."
proc_text = "I owe $*NUM* to *NUM* people for *NUM* *NUM* reasons."
text = "I owe $1,000.99 to 123 peo4ple for 2 +1 reasons."
proc_text = "I owe $*NUM* to *NUM* peo*NUM*ple for *NUM* *NUM* reasons."
assert cleantext.replace_numbers(text, "*NUM*") == proc_text


Expand Down