Hello I have a regex and its (^|\W)(t)|(t\W*year)($|\W)
my test case is
has to match
t-year
t
doesnt match
test123
but the problem for test123its matching it shouldn't match and also for t-year it is matching but only for t character
You can check from here https://regexr.com/6eqfi
CodePudding user response:
You might for example use
\bt(?:[^\w\s]year)?\b
\bA word boundary to prevent a partial word matchtMatch literally(?:[^\w\s]year)?Optionally match a non word character except for a whitespace char\bA word boundary
