59
rated 0 times
[
60]
[
1]
/ answers: 1 / hits: 18316
/ 13 Years ago, sun, january 29, 2012, 12:00:00
I have this regex on mongodb query to match words by prefix:
{sentence: new RegExp('^'+key,'gi')}
What would be the right regex pattern if I want it to match a sentence that has at least a word starting with key
prefix? For example:
If I have a sentence
This is a dog
when key
is 'do', then it should match that sentence since prefix 'do' is a substring of 'dog'.
My solution as of now only works for the first word of the sentence. It so far only matches that sentence if I type in 't' or 'th' or 'this'. It wouldnt match that sentence whenever I type in 'i' (prefix for 'is') or 'do' (prefix for 'dog').
More From » regex