6

I am coding an app to practice English, I need a javascript regular expression to find all the docs in a mongoDb collection on which the 'answer' property contains a word that ends in ing and exclude a few words from the match like everything, something, anything, nothing.

I have the following query right now:

{ '$or': [ { answer: /ing/i } ],
I20190303-13:26:00.915(-4)?   answer: /^(?!.*(\bsomething\b|\banything\b|\beverything\b|\bthing\b|\bnothing\b))/gi }

Unfortunately, my current query excludes strings like: 'I am doing nothing.' because nothing is in the text. But I would like texts like this to match because doing is present.

I want to get all the questions from the database whose answer contains one or more gerunds, unfortunately there are words that end in ing that are not gerunds.

Noel
  • 10,152
  • 30
  • 45
  • 67
Juan Pablo Fernandez
  • 2,408
  • 3
  • 18
  • 32
  • 1
    Good question. SUGGESTION (it's something you could easily do in "sed" or "awk"): 1) do a "text substitution" to ELIMINATE the words "something", "anything",etc. from the search string, 2) then - and only then - search the modified string for "ing". – paulsm4 Mar 03 '19 at 17:44

2 Answers2

1

Negative Lookbehind should work.

db.collection.find({
  "key": {
    $regex: "(?<!noth|anyth)ing",  //match ing, but not if it is part of nothing, anything
    $options: "i"
  }
})

Demo

Noel
  • 10,152
  • 30
  • 45
  • 67
1

You can use the following regular expression to find all documents in a MongoDB collection where the 'answer' property contains a word that ends in "ing" and exclude a few words like "everything", "som

/\b(?!(everything|something|anything|nothing)\b)\w+ing\b/gi

I hope this will solve your problem.

SahilDafda
  • 11
  • 1