prompt-toolkit / prompt-toolkit/python-prompt-toolkit

RegEx for detecting words are not handling special characters correctly

Open
#1,424 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
10.6k
Forks
815
PR merge metrics
No merged PRs in 30d

Description

Hi,

In document.py, the line:

FIND_WORD_RE = re.compile(r"([a-zA-Z0-9]+|[^a-zA-Z0-9_\s]+)")

will either detect words that are only alfanumericals or words that are only special characters, but not words that are a combination of the two. See attached image.
example regex bug

As shown in picture, words containing both alfanumericals and special characters are split into several words.

I suggest changing RegEx to:

_FIND_WORD_RE = re.compile(r"([^\s])+
example regex fix

as used later in document.py.

This would also fix issue 1280

Regards,
Trond

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in document.py at the _FIND_WORD_RE definition and compare it with the later regular expression mentioned in the issue. Reproduce the splitting of words that combine alphanumeric and special characters, then verify that the updated matching behavior also addresses issue 1280.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.