且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 RegEx 中使用单词边界 (\b) 我需要在单词之前和之后还是之前使用它?

更新时间:2023-09-01 13:26:10

您需要同时使用两者.如果没有最后一个 \b 你会得到一个匹配的字符串,例如:

You would need to use both. Without the last \b you would get a match on strings such as:

"I love football"
"You foolishly left off your second word boundary"