javascript - mongodb regex to find two words with exactly n or less words between them -


i want regex can query mongodb in following manner following results

  1. a x y b
  2. a x b
  3. a b

in short want regex finds 2 words n words or less between them.

here go:

/start( \w+){0,n} end/ 

example

/start( \w+){0,1} end/ 

matches

start word word word end // no match start word word end      // no match start word end           // match start end                // match 

edit

you should use

/^start( \w+){0,n} end$/ 

this takes better advantage of mongodb's indexes querys , faster non-indexed fields.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -