【发布时间】:2020-06-17 05:31:05
【问题描述】:
我希望创建一个允许一个或两个单词边界但不能为零的正则表达式。
例如,对于单词term:
-
a term is -
the terms are -
the midterm was -
the midterms were
这会是最好的正则表达式吗?我最初的想法是:
-
\bterm|term\b|\bterm\b#(\b上没有?)
但这似乎太冗长了。有什么更好的?
【问题讨论】:
-
@No -- 我可以重新输入以使其更清楚。
-
@CarySwoveland 已更新。
-
我想你只是想要
\bterm|term\b -
@Dai 是的,这是正确的,感谢您指出这一点。
-
@Dai 在 regex101 中运行良好。自己看:DEMO
标签: regex