Regex to match words in a sentence by its prefix

后端 未结 4 1557
礼貌的吻别
礼貌的吻别 2021-01-19 15:25

I have this regex on mongodb query to match words by prefix:

{sentence: new RegExp(\'^\'+key,\'gi\')}

What would be the right regex pattern

4条回答
  •  深忆病人
    2021-01-19 16:24

    Use the \b anchor to match word boundaries:

    \bdo
    

    finds 'do' in 'nice dog', but doesn't match 'much ado about nothing'.

提交回复
热议问题