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 -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -