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
- a x y b
- a x b
- 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
Post a Comment