DEV Community

Discussion on: How to find a string, within a string, using Regex

Collapse
 
saurabhdaware profile image
Saurabh Daware 🌻

/macport$|macport /g.test(string)

This will check for words having macport and a space appeneded or a string that ends with macport

for macports you can do the same thing by replacing macport with macports

I am on mobile so didn't check it much just check if it is working and I may have missed some cases

Collapse
 
saurabhdaware profile image
Saurabh Daware 🌻

Oh I replied with the sense that you want to differentiate between macport and macports, is this what you want?

Collapse
 
savagepixie profile image
SavagePixie

Oh, that's a very good point. It does change the answer.

Collapse
 
realabbas profile image
Ali Abbas

No, i want to include macport and macports both.

Thread Thread
 
saurabhdaware profile image
Saurabh Daware 🌻

oh then string.includes('macport') would work