Skip to content

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

Open
ratacat wants to merge 1 commit into
RanvierMUD:masterfrom
ratacat:patch-1
Open

update regex so it doesn't match substrings...such as 'linen' or 'phosphatidylcholine'#2
ratacat wants to merge 1 commit into
RanvierMUD:masterfrom
ratacat:patch-1

Conversation

@ratacat

@ratacat ratacat commented Mar 1, 2019

Copy link
Copy Markdown

No description provided.

@markscho

markscho commented Mar 1, 2019

Copy link
Copy Markdown

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

@shawncplus

Copy link
Copy Markdown
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

markscho commented Mar 1, 2019

Copy link
Copy Markdown

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

nahilep commented Mar 8, 2019

Copy link
Copy Markdown

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

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

@azigler

azigler commented Jun 27, 2020

Copy link
Copy Markdown

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