Regex to check if exact string exists

你离开我真会死。 提交于 2019-11-28 14:31:35

Your suggestion of /\bt\b/gi will work and is probably the way to go. You've correctly used \b for word boundaries. You're using the global and case-insensitive modifiers which will find all matches in both cases. Simple, straight forward, clean. Look no further than what you've already come up with.

Looks fine to me. You might want to check the exact meaning of the \b assertion to make sure it's exactly what you need.

Can't really name any situation where this pattern "wouldn't work" without a more elaborate description, but \b would work fine for your testcases.

According to the old saying give a man a reg expression and he is happy for a day, teach him to write regular expression and he is happy for a lifetime (or something to that effect) try out the "regulator"

It provides a GUI and some pretty good examples for reg exp needs.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!