prompt-toolkit / prompt-toolkit/python-prompt-toolkit
RegEx for detecting words are not handling special characters correctly
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.

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])+

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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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