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

update regex so it doesn't match substrings...such as 'linen' or 'phosphatidylcholine' #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ratacat
Copy link

@ratacat ratacat commented Mar 1, 2019

No description provided.

@markscho
Copy link

markscho commented Mar 1, 2019

Does this work if you type "IN" or "INTO"? Your RegEx isn't case insensitive (eg, /^into$/i).

@shawncplus
Copy link
Member

If we're only matching the specific words "in" and "into" IMO it would be better to toLowerCase() then do a direct === compare rather than using a regex.

@markscho
Copy link

markscho commented Mar 1, 2019

Or if you don't mind a few extra clock-cycles, you could do:
['in', 'into'].includes(arg.toLowerCase())
or for a tighter RegEx:
/^in$|^into$/i.test(arg)

@nahilep
Copy link

nahilep commented Mar 8, 2019

I would vote for a === comparison or includes()

NB: even tighter regex /^in(|to)$/i

@azigler
Copy link

azigler commented Jun 27, 2020

I accomplished this by modifying the regex like so:

const parts = args.split(' ').filter(arg => !arg.match(/\bin(|to)\b/i))

This matches "in" and "into", is case insensitive, and only matches a whole word.

I understand there's a lot of disdain for regex and it hinders code readability, but I found this approach to be simpler than doing a === comparison.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants