Regex match entire words only

后端 未结 7 1321
挽巷
挽巷 2020-11-21 05:35

I have a regex expression that I\'m using to find all the words in a given block of content, case insensitive, that are contained in a glossary stored in a database. Here\'s

7条回答
  •  逝去的感伤
    2020-11-21 06:28

    use word boundaries \b,

    The following (using four escapes) works in my environment: Mac, safari Version 10.0.3 (12602.4.8)

    var myReg = new RegExp(‘\\\\b’+ variable + ‘\\\\b’, ‘g’)
    

提交回复
热议问题