Skip to content

Tweak --ignore-regex to ignore consecutive matches - #2049

Open
peterjc wants to merge 2 commits into
codespell-project:mainfrom
peterjc:patch-1
Open

Tweak --ignore-regex to ignore consecutive matches#2049
peterjc wants to merge 2 commits into
codespell-project:mainfrom
peterjc:patch-1

Conversation

@peterjc

Copy link
Copy Markdown
Contributor

Consider this example for ignoring 2 or 3 letter upper case words (typical of acronyms):

codespell --ignore-regex '\W([A-Z]{2,3})\W'

If there are two consecutive matches in a string like "text TE OTU text" only one gets removed - the problem is the space needs to be used twice, the end of TE and the start of OTU as the second but overlapping regex match.

Cross reference #1578.

@peternewmanpeternewman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense thanks @peterjc .

Please can you add some tests for it so we won't regress in future (even if we change to a different workaround).

@peterjc

Copy link
Copy Markdown
ContributorAuthor

I wasn't sure if this change was in the spirit of the original regex implementation, but since you like the idea, I agree a test or two is a good idea.

@peterjc

Copy link
Copy Markdown
ContributorAuthor

I've tested this locally now:

$ codespell flag.txt flag.txt:1: TE ==> THE, BE, WE, TO
flag.txt:1: OTU ==> OUT
$ codespell --ignore-regex '\W([A-Z]{2,3})\W' flag.txt $ codespell --ignore-regex "\W([A-Z]{2,3})\W" flag.txt $ codespell --ignore-regex="\W([A-Z]{2,3})\W" flag.txt $ codespell --ignore-regex='\W([A-Z]{2,3})\W' flag.txt $ codespell --ignore-regex \W([A-Z]{2,3})\W flag.txt -bash: syntax error near unexpected token `('
$ codespell --ignore-regex=\W([A-Z]{2,3})\W flag.txt -bash: syntax error near unexpected token `('

Looks like the protective quotes are being lost somewhere in the test framework...

Consider this example for 2 or 3 letter upper case words
(typical of acronyms):
```
codespell --ignore-regex '\W([A-Z]{2,3})\W'
```
If there are two consecutive matches in a string like
"text TE OTU text" only one gets removed - the problem
is the space needs to be used twice, the end of `` TE ``
and the start of `` OTU `` as the second but overlapping
regex match.
@peterjc

Copy link
Copy Markdown
ContributorAuthor

Solved, rather than doing what works at the command line, I needed to match what Python receives from the command line.

Also rebased for a clearer history.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@peterjc@peternewman