Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有当前的正则表达式
/(?=.*?Joe)(?=.*?Doe).*/i
当我将它与 Joe Doe 匹配时,它返回 true,但是如何防止它匹配不以“Joe”或“Doe”开头的名称
即 Joe McDoe 应该返回 false。
/(?=.*?\bJoe)(?=.*?\bDoe)/
\b是一个单词中断。空格算作字符串的开头。
\b
你可以试试:
/(?=.*?\wJoe)(?=.*?\wDoe).*/i